0% found this document useful (0 votes)
5 views

OR - Ipynb - Colab

OR FeedForward program

Uploaded by

apaturkar87
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

OR - Ipynb - Colab

OR FeedForward program

Uploaded by

apaturkar87
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

16/10/2024, 21:26 OR.

ipynb - Colab

import numpy as np
def perceptron(x,y,learning_rate=0.01,epoch=1000):
weight=np.zeros(x.shape[1])
bias=0
for e in range(epoch):
for i in range(len(y)):
linear_output=np.dot(x[i],weight) + bias
y_prediction=1 if linear_output >= 0 else 0
if y_prediction!=y[i]:
update=learning_rate *(y[i]-y_prediction)
weight+=update*x[i]
bias+=update
return weight,bias
def predict(x,weight,bias):
linear_output=np.dot(x,weight) + bias
return([1 if i>=0 else 0 for i in linear_output])
x=np.array([[0,0],[0,1],[1,0],[1,1]])
y=np.array([0,1,1,1])
w,b=perceptron(x,y)
predictions=predict(x,w,b)
print("weight", w)
print("bias",b)
print("Predictions",predictions)

weight [0.01 0.01]


bias -0.01
Predictions [0, 1, 1, 1]

https://colab.research.google.com/drive/1fD9MhEpwJRdspg2JY7LNWfT3Ss4vNLrZ#printMode=true 1/1

You might also like