Vary k-nearest neighbor classification

조회 수: 1 (최근 30일)
Mark S
Mark S 2021년 5월 29일
답변: Image Analyst 2021년 5월 29일
Hello, I have written this little model for k-nearest neighbor classification:
knn_modell = fitcknn(cars, origin, 'NumNeighbors',k)
resubLoss (knn_modell)
calculated_knn1 = predict(knn_modell, cars)
truthmatrix = confusionmat(originarray, calculated_knn1)
So far so good. But now I wanna vary k between 1 and 20. How can I do that in matlab? And I want to make a graph of resubstitution loss as a function of k. Is this possible at all in Matlab?

답변 (1개)

Image Analyst
Image Analyst 2021년 5월 29일
Yes. just put it in a for loop
for k = 1 : 20
% Code...
end

Community Treasure Hunt

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

Start Hunting!

Translated by