Greetings I have posted a snippet of code below Find the top

Greetings!

I have posted a snippet of code below:

%Find the top k nearest neighbors, and do the voting.

[B,I] = sort(dist);

posCt=0;
negCt=0;
for ii = 1:k
if train_label(I(ii)) == 1
posCt = posCt + 1;
elseif train_label(I(ii)) == 0
negCt = negCt + 1;
end
end

if posCt >= negCt
pred_label = 1;
else
pred_label = 0;
end

Anyways, I am supposed to do a report now and I am having trouble understanding this question:

\"Analyze Hyperparameter K in the KNN part, which K you empirically observed that could achieve the best performance?\"

I believe the snippet I posted is the part its talking about, but I am not sure what it means.

Solution

it does not related with the snapshot u posted

K should be square root of n where n is the total number of sample

by keeping k=square root of n will achieve best performance

Greetings! I have posted a snippet of code below: %Find the top k nearest neighbors, and do the voting. [B,I] = sort(dist); posCt=0; negCt=0; for ii = 1:k if tr

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site