convert knnclassify to fitcknn
Afficher commentaires plus anciens
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 commentaires
Walter Roberson
le 4 Mai 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
le 5 Mai 2021
Walter Roberson
le 5 Mai 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
le 5 Mai 2021
Walter Roberson
le 5 Mai 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
le 6 Mai 2021
Walter Roberson
le 6 Mai 2021
And I already answered you at https://www.mathworks.com/matlabcentral/answers/505383-how-can-i-convert-knnclassify-to-fitcknn#comment_1502310
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


