Perceptron Notes
Perceptron Notes
a biological neuron
Dendrites
it
Eg
ma
p you
Biologicalluron
In brain you hamefollection of neurons and each neuron
2 Wini b
activation fan
i g
9 86
activation fun
Artificial Neuron
In this
lecture we will see what is a Perceptron
Perceptron is a single layer neural network We will
about the
be learning loss function and later on we
will derive weight update rule
w no win when
if
a
mme w
Activation
fan
I
Ilnsin
oca.tt
OpisFany no bw o and I
g
we
classification
close to 0
2 ID
for
012
Ply 1 z
P y O 1 012
Z W x
with 0.3
probability it
belongs to class
Dog it belongs
to class cat with
probability 0.7
y 1 1 1 0 0
MSE j yes
w
JCW
thisfficulty
To overcome we use another
kind of loss called as
log loss
y ng j r
y log r j
It is a
then loss
for log r
j
if y
i
note freedrichtonstheane
we add
yn
then loss
fan log log of misclassification
i
if y O and j O
if y I and j
i
I
then loss 0
fx
II iv
Start with some random w and w as
update
we
Gradient update Rule
is
a
a
fan of Jci
fan of wTx i
GRADIENT DESCENT UPDATE
In the last lecture we about loss function to
talked
train a perceptron and how perceptron acts as a
binary
classifier In this video our aim is to derive weight
update rule that will help us to find optimal set of
parameters w for the perceptron and we will use gradient
descent update rule to update the parameters
w Em y log j 1 y log i
g's
FPunction
goaeistolearmw
FEItndn.tt mÉtthEann
at some
f whd
Ñdom
up optimal
This can be done by using
Gradient update rule which
repeatedly decreases our loss in the w w
direction of reducing gradient
W wn
wo W wa n no
of features
C1
chain rule
Eg
for
amke f FF send east rs age 5
notifier
Ti.IE c
j 06 2
E E 5 012
j o
8 z r o z
j o z i 2
j j r j
2 Wtx
z No Wise win Whan
ni
i
f JE
Ey t LED a
f f
j y xi
feature for
ith
win
Offit y ni
given a example
wj Wj y É j yes af
7
update the jth
gradient
Learning Goals
CODE
import numpy as up
import matplotlib pyplot as felt
from sklearn datasets import make_blobs
Generating Data
x Y make_blobs
I returns gaussian blobs
pet scatter 0 1 C Y
chap pet.cm Accent
pet show
it is linearly
separable data
wÉ Goal of perception
v learning algo
1
is to figure out
boundary which
separates data
into 2 classes
def sigmoid z
2
up array 1,2 3 4,5
sigmoid 2
7
you will get an array
This kind of functionality is called broadcasting
1
It is possible only in numpy array
Numpy does it b.cz ofa technique called
as broadcasting
sigmoid z
g I
return
Effort
predictions
mx nti
matrix
Wnx vector
Wj Wj 7
Y predict x weights j
a y
np.at y
y.p
g
m Shape 0
weights weights learning rate du float m
return weights
EEE I
MXI
y y
E
ji_
µ11
nxm mxl
j y x
def train x Y
learning rate 0.5 max Epochs 100
x
ones
up ones shape 0 s
Jmx
up hstack Cones
b
F Init weights
f
o 9,1494m
if epoch7.10 0
after every
10 epochs l loss x Y weights
the
print
progress print Epoch 7d loss To 4f 7 epoch e
return weights
train x Y
is Reducing
Joss
weights learnt by your
i classifier for n features
we will have n I
T T T weights
weights train x Y max Epochs 500
do oh
ÉdwhÉg
Loss is close to 0
VISUALISING DECISION SURFACE
We are
building a simple neural network by training
one perceptron We will see how to make predictions
all data and also visualise the
for points hypothesis
generated by our
algo We will run this perceptron over
a non linear dataset and will see the results
wo.co won
if not labels
return frobs W
we Mds shake
Pires
output of algo is
return labels to be a
going
fffisifY
All the places where I
a up zeros 55
a 2 3 10
print a
a a 0 20
print a
weights
feet Scatter X 0 I C Y
map feet cm Accent
flt show
No Ws wz
000
two
fed
see
If we plot 22 V S
this
x2 using
formula we will
get the line
8 2,10
x1
up linspace
x2 weights 0 weights I xD weights 2
pet Scatter X 0 1 C Y
map pet ons Accent
pet plot x1 x2 C red
pet show C
We are able to
separate the data
Lets
try with different value of random state
print Y
comparison
fruit
500
7
Training Accuracy is 1007
All predictions are correct
Wyway
learn a
very good
boundary bcz data
my yummy
some other hypothesis
which should be
able to separate
data like this
This kind of boundary
can be learnt by
MLP Multi Layer
Perceptron
now
accuracy is only 86.8
Some points are not
classified
correctly