Dogggg / accord

Automatically exported from code.google.com/p/accord
0 stars 0 forks source link

KNearestNeighbor should not assume zero-based consecutive class labels #17

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
KNearestNeighbor should not assume zero-based consecutive class labels. If the 
labels (the outputs parameter of the constructor) happens to be something like 
{4, 2, 5} (does not have zero and does not include all labels from 0 - 5), the 
method Compute crashes.

Attached is a modified version of the class that works with this use case 
without the problem.

Original issue reported on code.google.com by Thanacha...@gmail.com on 2 Nov 2012 at 12:14

Attachments:

GoogleCodeExporter commented 8 years ago
Many thanks for the feedback and the patch. However, most methods in the 
framework are made to work with zero-based class indices by design (they are 
treated as indices, after all). The issue I see with the Nearest Neighbor class 
is due to its constructor. I should have added a constructor with a classCount 
parameter instead of relying on counting distinct instances from an output 
label vector. My bad.

Do you think this would help solving the problem?

Original comment by cesarso...@gmail.com on 2 Nov 2012 at 2:36

GoogleCodeExporter commented 8 years ago
If that is the case, we can just take the max of all the class labels, add one 
to it, and the result is the classCount we need...

Original comment by Thanacha...@gmail.com on 2 Nov 2012 at 2:51

GoogleCodeExporter commented 8 years ago
Fixed on Accord.NET 2.8.

Original comment by cesarso...@gmail.com on 6 Nov 2012 at 5:23