0% found this document useful (0 votes)
11 views4 pages

DL Week 1-1

The document outlines the implementation of a Single Layer Perceptron and MP neurons for logical AND and OR operations using Python. It includes code snippets for each implementation along with the expected outputs. Additionally, it demonstrates a simple Perceptron with custom weights and inputs, providing the corresponding output.

Uploaded by

prannu2006
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)
11 views4 pages

DL Week 1-1

The document outlines the implementation of a Single Layer Perceptron and MP neurons for logical AND and OR operations using Python. It includes code snippets for each implementation along with the expected outputs. Additionally, it demonstrates a simple Perceptron with custom weights and inputs, providing the corresponding output.

Uploaded by

prannu2006
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/ 4

Name DEEPTHI DASARI Expno&Exp 1.

SINGLE LAYER
Name PERCEPTRON

Roll no 22R21A0580 Date 25-01-2025


1.Implement Single Layer Perceptron in Python.

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:

3. Implement MP neuron for Logical OR.

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:

4. Implement a simple Perceptron with custom weights, inputs,


and a threshold.
Input=[0.1, 0.5, 0.2]
Weights=[0.4, 0.3, 0.6]
Threshold=[0.5].
PROGRAM:
import numpy as np
x_input=[0.1,0.5,0.2]
w_weights=[0.4,0.3,0.6]
threshold=0.5
def step(weighted_sum):
if weighted_sum>threshold:
return 1
else:
return 0
def perceptron(x_input,w_weights):
weighted_sum=0
for x,w in zip(x_input,w_weights):
weighted_sum+=x*w
print("Weighted Sum:",weighted_sum)
return step(weighted_sum)
output=perceptron(x_input,w_weights)
print("Output",output)
OUTPUT:

You might also like