ML Lab3 PGM
ML Lab3 PGM
Write a Python program to load whether data set and apply a perceptron learning
algorithm to determine whether the rain occurs tomorrow or not.
Artificial Neural Networks (ANNs) are the new trend for all data scientists. From classical
machine learning techniques, it is now shifted towards deep learning. Neural networks mimic
the human brain which passes information through neurons. Perceptron is the first neural
network to be created. It was designed by Frank Rosenblatt in 1957. Perceptron is a single
layer neural network. This is the only neural network without any hidden layer. Perceptron is
used in supervised learning generally for binary classification.
The above picture is of a perceptron where inputs are acted upon by weights and summed to
bias and lastly passes through an activation function to give the final output.
import numpy as np
from sklearn.datasets import load_iris
iris = load_iris()
iris.target_names
OUTPUT:
array(['setosa', 'versicolor', 'virginica'], dtype='<U10')
Iris setosa
not Iris setosa, or in other words either 'viriginica' od
'versicolor'
O UT PU T:
[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0]
O UT PU T:
Perceptron(max_iter=10, random_state=42)
Now, we are ready for predictions and we will look at some randomly
chosen random X values:
import random
O UT PU T:
102 [0]
86 [0]
89 [0]
16 [0]
108 [0]
87 [1]
98 [1]
82 [0]
39 [0]
118 [0]
print(classification_report(p.predict(train_data),
train_labels))
O UT PU T:
precision recall f1-score support
print(classification_report(p.predict(test_data),
test_labels))
OUTPUT:
precision recall f1-score support
accuracy 1.00 30
macro avg 1.00 1.00 1.00 30
weighted avg 1.00 1.00 1.00 30