DL Week 1-1
DL Week 1-1
SINGLE LAYER
Name PERCEPTRON
PROGRAM:
import numpy as np
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.linear_model import Perceptron
from sklearn.metrics import accuracy_score
d=load_iris()
x=d.data
y=d.target
xt,xtt,yt,ytt=train_test_split(x,y,test_size=0.2,random_state=42)
c=[]
for I in np.unique(y):
b=np.where(yt==I,1,0)
p=Perceptron(max_iter=100,random_state=42)
p.fit(xt,b)
c.append(p)
pred=np.array([clf.predict(xtt) for clf in c])
fp=np.argmax(pred,axis=0)
a=accuracy_score(ytt,fp)
print("Accuracy:",a)
OUTPUT:
2.Implement MP neuron for Logical AND.
PROGRAM:
import numpy as np
inputs=[1,1]
threshold=2
def step(input_sum,threshold):
if input_sum>=threshold:
return 1
else:
return 0
def mp_neuron(inputs,threshold):
input_sum=sum(inputs)
print("input_sum",input_sum)
return step(input_sum,threshold)
output=mp_neuron(inputs,threshold)
print("Neuron output:",output)
OUTPUT:
PROGRAM:
import numpy as np
inputs=[[1,1],[1,0],[0,1],[0,0]]
threshold=1
def step(input_sum,threshold):
if input_sum>=threshold:
return 1
else:
return 0
def mp_neuron(inp,threshold):
input_sum=sum(inp)
print("input_sum",input_sum)
return step(input_sum,threshold)
for inp in inputs:
output=mp_neuron(inp,threshold)
print("Neuron output:",output)
OUTPUT: