Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Greetings! I have posted a snippet of code below: %Find the top k nearest neighb

ID: 3789736 • Letter: G

Question

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.

Explanation / Answer

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