Skip to content

Perceptron classifier with 3D plot live visualisation of learning process in Python

Notifications You must be signed in to change notification settings

szymicorp/perceptron

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Perceptron classifier with 3D plot live visualization in Python

Mathematical representation of neuron

Neuron receives and analysis data from dendrites. It performs simple biological tasks to support thinking processes in brain. Perceptron is artificial representation of it. To understand the artificial concept, image below shows real neuron described by math.

X
1-dimensional matrix of input values
W
1-dimensional matrix of weights
Θ
bias

Now, we know how perceptron is build. Next thing we need is formula to generate output. Output is discrete and unipolar -> {0,1}. Output will be produced by this formula:
equation

To understand it well, let's simplify it. We can now set equation and equation . Now, formula will look like this:
equation
From matrix multiplication rules we know that equation will return integer. Whether this integer is less then 0 or more, we can classify this data sample to class 0 or 1.

Changing value of Θ will move our red hyperplane from (0,0). This will help to divide data into classes if we needed so:

Perceptron learning process

As we already know, X represents inputs - they change all the time. W and Θ are internal components of perceptron. So, learning process will be based on changing values of them. W will point where one class is and will define angle of hyperplane, Θ it's distance from (0,0).
When we train our perceptron, we use supervised training, which means we know right answers for data we provide to perceptron. If guess of perceptron is right, we continue with training, but when it is wrong, we want it to calibrate W and Θ values.

W training formula:

equation

W'
new vector
W
old vector
d
desired output {0,1}
y
perceptron output {0,1}
alpha
training factor
X
vector of inputs

Θ training formula:

equation

When perceptron training process is done, when reviewing 3D scatter plot, plane from vector and point (W and Θ) should look like this:

Program workflow

1. Input files

Provide path to train set and test set. Both should:

  • be .csv files
  • contain same number of columns in the same order
  • have last column containing class

Load data. If files were read correctly, input fields should appear green.

2. Training and testing

When data has been loaded properly, next step is to set value of alpha. Then, you can start process of training perceptron with train set data. This is all done by clicking "Train perceptron" button. 3D scatter plots should appear. They represent every 3D projection of all data dimensions. For example, if your data has 4 numeric columns, equation plots should appear.
On these 3D plots, you can observe how W plane is changing due to learning process (including Θ). Currently computed data sample is highlighted with red.
When learning process is done, you can test accuracy of trained perceptron with test set data. Scores of tests will be shown afterwards.

3. Classify data

If you are happy with scores of perceptron classification, here you can classify unclassified samples. Csv format required.

About

Perceptron classifier with 3D plot live visualisation of learning process in Python

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages