Perceptron is a linear classification model of two classes, which belongs to the discriminant type, which is the basis of neural network and support vector machine.
Algorithm of the perceptual machine:
According to the above algorithm, using MATLAB to train a group of data labeled "1" and "1" to get the classification of super-plane.
The data are:
%%Perceptronclcclear%load the data import=load ('TestSet.txt');%sometimes DoNot need too precise data% Data=roundn (data,-1); x=[data (:,1), data (:,2)];y=data (:,3); K=length (y);%plot The data point based the label to draw a scatter plot based on the label of the data forj=1: KifY (j) = =1plot (X (J,1), X (J,2),'o');% l={num2str (j)};% text (x (J,1), X (J,2), L); Hold on endifY (j) ==-1plot (X (J,1), X (J,2),'x');% l={num2str (j)},% text (x (J,1), X (J,2), L); Hold on end end%Initialize the parameters initialization parameter, corresponding to the first step of the algorithm W=[0,0];b=0; R=0.5; %Learningratecon=0; %SetThe Conditiont=0; %record the number of ITERATIONSBR=[]; %record The change of BWR=[]; %record The change of W whilecon==0% condition for training set no mis-classification points forI=1: Kif(Y (i) * (dot (w,x (i,:)) +b) <=0% determine if the classification is incorrectW (1) =w (1) +r*y (i) *x (i,1); % corresponding algorithm the third step W (2) =w (2) +r*y (i) *x (i,2); b=b+r*y (i); W=[w (1), W (2)]; WR=[Wr;w]; BR=[Br,b]; T=t+1;EndEnd forI=1: K Con1 (i)= (Y (i) * (dot (w,x (i,:)) +b)); % if all points are classified correctly, then all elements in Con1 are greater than 0 end con= (All (Con1 (:) >0)) Endxt=-2:0.1:Ten; % draw the category plane YT= (-W (1) *xt-b)/w (2);p lot (XT,YT);
Running the above program, the results are as follows:
MATLAB implementation of [machine learning] Perceptron (Perceptron) algorithm