convert knnclassify to fitcknn
Show older comments
please help me to convert knnclassify to fitcknn
x=readtable("datatraining.xlsx");
latih=x;
group=latih(:,3);
latih = [latih(:,1) latih(:,2)];
for i = 1 : 80
y=readtable("datatesting.xlsx");
sampel = y;
test = [sampel(:,1) sampel(:,2)];
%sampel = [2.6136 0.1284 1.3017 -0.8089 0.0441 -0,2084];
hasil=knnclassify(test,latih,group);
end
nama = "hasil KNN.xlsx";
hasil = [sampel(:,1) sampel(:,2) sampel(:,3) hasil];
xlswrite(nama,hasil);
7 Comments
Walter Roberson
on 4 May 2021
Do not read files inside a loop -- not unless you are reading a different file each time.
The body of your loop does not use i, so you are doing the same thing each iteration.
Frisda Sianipar
on 5 May 2021
Walter Roberson
on 5 May 2021
x=readtable("datatraining.xlsx");
y=readtable("datatesting.xlsx");
latih=x;
group=latih(:,3);
latih = [latih(:,1) latih(:,2)];
for i = 1 : 80
sampel = y;
test = [sampel(:,1) sampel(:,2)];
%sampel = [2.6136 0.1284 1.3017 -0.8089 0.0441 -0,2084];
hasil=knnclassify(test,latih,group);
end
nama = "hasil KNN.xlsx";
hasil = [sampel(:,1) sampel(:,2) sampel(:,3) hasil];
xlswrite(nama,hasil);
except rewritten to use fitcknn as discussed in your other postings.
Frisda Sianipar
on 5 May 2021
Walter Roberson
on 5 May 2021
Why did you go back to knnclassify() ? You were given conversion information at https://www.mathworks.com/matlabcentral/answers/505383-how-can-i-convert-knnclassify-to-fitcknn#comment_1500660
Frisda Sianipar
on 6 May 2021
Walter Roberson
on 6 May 2021
And I already answered you at https://www.mathworks.com/matlabcentral/answers/505383-how-can-i-convert-knnclassify-to-fitcknn#comment_1502310
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

