Simple Perceptron algorithm in matlab: cannot draw the classifier line

조회 수: 5 (최근 30일)
Hieu Nguyen
Hieu Nguyen 2018년 9월 16일
댓글: Hieu Nguyen 2018년 9월 16일
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!
  댓글 수: 2
Kaushik Lakshminarasimhan
Kaushik Lakshminarasimhan 2018년 9월 16일
편집: Kaushik Lakshminarasimhan 2018년 9월 16일
There is no reference to the variable b. I can only assume that it is loaded from data1.mat file. You need to make sure b is scalar.
Hieu Nguyen
Hieu Nguyen 2018년 9월 16일
I fixed the code. I moved the definitions of b and d before x1 and x2 but there is still not line drawn from the plot(x1,x2)

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by