Ask Your Question
0

How to put a label of type string in a matrix (KNN)

asked 2016-04-15 06:59:33 -0600

siline gravatar image

updated 2016-04-15 07:00:05 -0600

This line put a label for a trainData mat

train_labels.push_back(new Mat (1,1,CvType.CV_32FC1,new Scalar(i)))

I would put a string label instead of a float label .is it possible ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-04-15 07:20:28 -0600

berak gravatar image

no, you cannot do this.

instead, use a lookup table of strings, and use the prediction / label value as index, maybe like this:

String lut [] = {"apples", "pears", "oranges"};
int predicted = knn.findNearest( testData, 3);
String fruit = lut[predicted];

(btw, you should use integer labels for KNearest, not float)

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-04-15 06:59:33 -0600

Seen: 241 times

Last updated: Apr 15 '16