Learn practical skills, build real-world projects, and advance your career
Created 3 years ago
My First Neural Network!
It prints out the accuracy of what the Neural Network Thinks
By the way No time to explain the algorithm in detail
It is an "inclusive_or" perceptron. Please search it you have any doubts.
import numpy as np
learning_rate = 1
bias = 1
weights = np.random.rand(3)
def accuracy(error):
if error == 0:
print("100%")
if error == -1:
print("0%")
def perceptron(neurons, desired_output):
output_of_perceptron = np.dot(neurons, weights)
#Activation Function
if output_of_perceptron > 0:
'''if calculated output is positive then'''
output_of_perceptron = 1
else:
'''otherwise'''
output_of_perceptron = 0
#error calculation
error = desired_output - output_of_perceptron
#updating the weights
weights[0] += error * neurons[0] * learning_rate
weights[1] += error * neurons[1] * learning_rate
weights[2] += error * neurons[2] * learning_rate
#Printing the accuracy..
accuracy(error)
for i in range(10):
#input neurons, labels
perceptron( [1,1,bias], 1 ) #True
perceptron( [1,0,bias], 1 ) #True
perceptron( [0,1,bias], 1 ) #True
perceptron( [0,0,bias], 0 ) #False
100%
100%
100%
0%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%