I am new to Matlab and I am trying to test my learning curve by writing the perceptron algorithm from scratch. I have seen this in R but I think it is fun to try out Matlab. It seems to me that I cannot draw the classifier line.
load data1.mat w_0 = [1;-1]; for iteration = 1 : 100 %<- I do not know how to define a convergence or stopping criteria for ii = 1 : size(X,2) %cycle through training set if sign(w'.*X(:,ii)) <=0 %wrong decision? w = w + X(:,ii) * y(ii); %then add (or subtract) this point to w end end end x1 = [-1,b]; x2 = [1,d]; b = w(1)/w(2); d = -w(1)/w(2); scatter(X(:,1),X(:,2),50,y,'*'); hold on;plot(x1,x2);hold off
My data set ("data1.mat") has X as the feature matrix of 40x2 and y. I want to plot the boundary line i.e the line w^Tx = w_1*x_1 + w_2*x_2 = 0. I just choose 2 points p1 = (a,b) and p2 = (c,d). Since my data limits x_1 and x_2 between -1 and 1, I choose a = 1 and c = -1 and find out b and d.
But still, the syntax looks normal to me but I have an error:
Error using horzcat Dimensions of matrices being concatenated are not consistent.
Error in Myperceptron (line 12) x1 = [-1,b]; Thanks!