Perceptron Learning Algorithm Demo - MATLAB

less than 1 minute read

Code available here

This is the MatLab implementation of the popular basic classification algorithm known as Perceptron Learning Algorithm(PLA)

The purpose is to show how PLA converges to its final hypothesis

  • For a linearly seperable dataset PLA converges to one final hypothesis with perfectly classified classes
  • For a linearly inseperable dataset PLA does not converge to any hypothesis and we choose the hypothesis of the last iteration as out final hypothesis

Running the code

Linearly seperable

  • In the main.m file change the ‘type’ variable to 1 to create linearly seperable points
  • Change ‘numpoints’ variable to the number of datapoints to be taken
  • In the MatLab command line run the command

    main.m
    

    alt

    Linearly inseperable

  • In the main.m file change the ‘type’ variable to 0 to create linearly inseperable points
  • Change ‘numpoints’ variable to the number of datapoints to be taken
  • In the MatLab command line run the command

    main.m
    

    alt

    Result

    Linearly seperable

    alt

The PLA converges to a hypothesis in case of linearly seperable. The final hypothesis division is represented by the green line.

Linearly inseperable

alt

The PLA does not converge in case of linearly inseparable, the magenta line represents the final hypothesis achieved after 5000 steps