I have a knn classifier that finds the k nearest neighbors of the given data. While classification I am not able to handle ties. I want to handle ties in the following way:
If there is only one class and it is correct class accuracy is 1
If there is only one class and it is incorrect class accuracy is 0
If there is more than one class tied for best and the correct class is one of those then accuracy = 1/no_of_classes_tied_for_best.
How do I do this in Matlab?
Code till now: test has my knnclassify results for 5 neighbors
classes_test has my verification class.
for i = 1:size(test,1) set = 0; for j = 1:size(test,2) if test(i,j) == classes_test(i,1) && set~=1 set = 1; accuracy = accuracy + 1; end end end