I'm new using matlab, my goal is to implement knn, I have two differents txt files, one contains test data(sample) and the other one contains training data.
So far I think I should do something like this, but I'm not sure how to do it.
load fisheriris
x = meas(:,3:4);
gscatter(x(:,1),x(:,2),species)
newpoint = [5 1.45];
[n,d] = knnsearch(x,newpoint,'k',10);
line(x(n,1),x(n,2),'color',[.5 .5 .5],'marker','o','linestyle','none','markersize',10)
Or maybe this is a more simple way to do it, to me that's very clear the two different sets of data, sample and training, but this doesn't show the accuracy of the predicted class.
A= [50, 60;
7,2;
13,12;
100,200;];
B=[1,0;
200,30;
19,10];
G={'First Row';
'Second Row';
'Third Row'};
class = knnclassify(A,B,G);
disp('Result: ');
disp(class);
the matrix looks like this:
Training data:
148.0,50.0,0
187.0,34.0,0
204.0,89.0,0
430.0,161.0,1
427.0,22.0,1
-42.0,469.0,1
more,more,class....
Test data:
290.0,-57.0,0
194.0,-80.0,0
174.0,33.0,0
465.0,691.0,1
270.0,-194.0,1
-56.0,665.0,1
more,more,class....
How can I classify this data using knn and show the predictions for each row so I can calculate the accuracy percentage?
-------EDITED------
I forgot, if I need the accuracy for each class, what should I do?