gnu-octave / statistics

The Statistics package for GNU Octave
GNU General Public License v3.0
24 stars 22 forks source link

Error in Creating KNN classifier with explicit ClassNames #148

Closed ruchikasonagote closed 2 months ago

ruchikasonagote commented 2 months ago

I encountered an error while attempting to create a K-Nearest Neighbor classifier using the Iris dataset. The error message indicates a problem with the 'N' parameter, specifically: image

Code Snippet:

load fisheriris
X = meas;
Y = species;
ClassNames = {'setosa', 'versicolor', 'virginica'};
Mdl = fitcknn (X, Y, 'ClassNames', ClassNames);

Expected Behavior: The fitcknn function should create a KNN classifier object.

dasergatskov commented 2 months ago

I do not understand what the code does, but ac = find (gnY, ClassNames{i}) looks wrong, perhaps it should be ac = find (strcmp(gnY, ClassNames{i})) ?

pr0m1th3as commented 2 months ago

Thanks @dasergatskov for pointing this out. I included the above code snippet as a unit test.