Closed oveddan closed 5 years ago
If you create a knn classifier and add some classes that are not at the beginning, then run predictClass, you get a -1 class and some NaN confidence levels:
Sample code:
import * as knnClassifier from '@tensorflow-models/knn-classifier'; const testClassifications = async () => { const classifier = knnClassifier.create(); classifier.addExample(tf.tensor2d([5, 2], [2, 1]), 1); classifier.addExample(tf.tensor2d([6, 1], [2, 1]), 2); const result = await classifier.predictClass(tf.tensor2d([3, 3], [2, 1])); console.log(result); } testClassifications();
Result is:
{ classIndex: -1, confidences: { 1: 0 2: NaN } }
Thanks. Sent a fix in https://github.com/tensorflow/tfjs-models/pull/188
Hi Dan, we just released a new version of knn-classifier (1.1.0) on npm that supports arbitrary strings or numbers as class labels.
If you create a knn classifier and add some classes that are not at the beginning, then run predictClass, you get a -1 class and some NaN confidence levels:
Sample code:
Result is: