Created
July 19, 2021 09:25
-
-
Save ViniTheSwan/bf77ec751ee6425def038d975fb532be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# making an instance of a neuron | |
neuron = Perceptron(input_size = 3, learning_rate = 0.05) | |
#training samples | |
X_train = np.array([[1,0,0,1,1,0,1,0], | |
[0,1,0,1,0,1,1,0], | |
[0,0,1,0,1,1,1,0]] ) | |
#training label | |
y_train = np.array([ 1, 0, 0, 1, 1, 0, 1, 0]) | |
#test sample | |
X_test = np.array([[1], | |
[1], | |
[0]]) | |
#test label | |
y_test =np.array( [ 1 ]) | |
#number of epochs i.e. number of times we train on the whole dataset | |
n_epochs = 30 | |
#training loop | |
for epoch in range(n_epochs): | |
for i in range(X_train.shape[1]): | |
x = X_train[:,i] #slice only one column | |
y = y_train[i] #slice only one column | |
neuron.train(x,y) | |
#test loop | |
for i in range(X_test.shape[1]): | |
y_hat = neuron.forward(X_test[:,i]) | |
y_true = y_test[i] | |
print(f"Test: \npredicted y: {y_hat.squeeze()}, true y: {y_true}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment