First time here? Check out the FAQ!

Ask Your Question
0

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

asked Apr 15 '16

siline gravatar image

updated Apr 15 '16

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 ?

Preview: (hide)

1 answer

Sort by » oldest newest most voted
1

answered Apr 15 '16

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)

Preview: (hide)

Question Tools

1 follower

Stats

Asked: Apr 15 '16

Seen: 247 times

Last updated: Apr 15 '16