A Step by Step Process of a Simple Perceptron Example

By: Roth P. In


Import library
matplot for graphs visualization

Data
Create dataset and plot on matplot grap for visualization

Create the First Perceptron

Parameters and Inputs
Weights and learning rate are parameters, X is the input.

Perceptron Basic Formula
$ y = \sum \limits _{i=1} ^n x_{i}w_{i} $

If y > 0 => class red, otherwise class blue.



$ w_{0} = 0, w_{1} = 1, w_{2} = \frac{1}{2}$

  1. $ w_{0}x_{0} + w_{1}x_{1} + w_{2}x_{2} > 0$

  2. $ x_{1} + \frac{1}{2}x_{2} > 0 $

  3. $ x_{2} > -2x_{1} ≈≈> y = -2x$

Plot the Line
Plot the line to separate the classes.

Update Perceptron

$ w'_{i} = w_{i} + n * d * x_{i} $

n is learning rate (parameter)
d is 1 if the missed point should above the line, 0 otherwise.

For this example, 0.25 is n
For the misclassify point above is class blue at (2, -2), so d would be -1

After update
The new weights are $ w_{0} = \frac{-1}{4}, w_{1} = \frac{1}{2}, w_{2} = 1$

  1. $ w_{0}x_{0} + w_{1}x_{1} + w_{2}x_{2} > 0$

  2. $ \frac{-1}{4} + \frac{1}{2}x_{1} + x_{2} > 0 $

  3. $ x_{2} > \frac{-1}{2}x_{1} + \frac{1}{4} ≈≈> y = \frac{-1}{2}x + \frac{1}{4} $

Plot the Updated Line