Classification of linearly separable data with a perceptron

Neural Networks course (practical examples) © 2012 Primoz Potocnik

PROBLEM DESCRIPTION: Two clusters of data, belonging to two classes, are defined in a 2-dimensional input space. Classes are linearly separable. The task is to construct a Perceptron for the classification of data.

Contents

Define input and output data

close all, clear all, clc, format compact

% number of samples of each class
N = 20;
% define inputs and outputs
offset = 5; % offset for second class
x = [randn(2,N) randn(2,N)+offset]; % inputs
y = [zeros(1,N) ones(1,N)];         % outputs

% Plot input samples with PLOTPV (Plot perceptron input/target vectors)
figure(1)
plotpv(x,y);

Create and train perceptron

net = perceptron;
net = train(net,x,y);
view(net);

Plot decision boundary

figure(1)
plotpc(net.IW{1},net.b{1});