MATLAB implementation of [machine learning] Perceptron (Perceptron) algorithm

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.