import sklearn.datasets

import numpy as np

import pandas as pd

from sklearn.model_selection import train_test_split

breast_cancer=sklearn.datasets.load_breast_cancer()

X=breast_cancer.data

Y=breast_cancer.target

data1=pd.DataFrame(breast_cancer.data,columns=breast_cancer.feature_names)

data=data1.copy()

data.describe()

data[‘class’]=breast_cancer.target

data[‘faltu’]=data[‘mean radius’]

col = data.columns

sub=[‘faltu’]

final=list(set(col)-set(sub))

new_data=data[final]

new_data.columns

X=new_data.drop([‘class’],axis=1)

Y=new_data[‘class’]

x_train,x_test,y_train,y_test=train_test_split(X,Y,test_size=0.2,stratify=Y)

#perceptron model

#making class of perceptron

class perceptron:

def __init__(self):

```
self.w=None
self.b=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\]) #vfghhjhjhj
self.b=0
for x,y in zip(X,Y):
y\_pred = self.model(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
```