class Perceptron:
def \_\_init\_\_(self):
self.b=None
self.w=None
def model(self,x):
return 1 if (np.dot(self.w , x)>=self.b ) else 0
def predict(self,X):
Y=\[\]
for x in X:
result=self.model(x)
Y.append(result)
return np.array(Y)
def fit(self,X,Y):
self.w=np.ones(X.shape\[1\])
self.b=0
for x,y in zip(X,Y):
y\_pred=self.predict(x)
if y==1 and y\_pred==0 :
self.w=self.w+x
self.b=self.b+1
elif y==0 and y\_pred==1:
self.w=self.w-x
self.b=self.b-1