First time here? Check out the FAQ!

Ask Your Question
0

I cannot train data using knn

asked Apr 5 '16

bob409 gravatar image

updated Apr 6 '16

berak gravatar image

I am getting this error:

OpenCV Error: Assertation failed <samples.type<>CV_32F || samples.type<>CV_32S> in cv::ml::TrainDataImpl::setData

I have extracted feature and placed it in a String;

//for loop

String features = "352111653512146120635735005";

Mat m;
    m.push_back(features);
    m.reshape(1, 1);

    freeman.push_back(m);
             labelMat.push_back(label);

             Ptr<ml::KNearest> knn = ml::KNearest::create();
        Ptr<ml::TrainData> td = ml::TrainData::create(feature, ml::ROW_SAMPLE, label);  <-----I am getting error here
Preview: (hide)

1 answer

Sort by » oldest newest most voted
2

answered Apr 5 '16

berak gravatar image

updated Apr 5 '16

  • you cannot add "String" features,they have to be a Mat(or a vector of) numbers . [what you're trying to feed in currently, is the ascii representation of the number. that won't ever work.]
  • machinelearning wants float data. you either have to convert, or read in your data as float.
Preview: (hide)

Question Tools

1 follower

Stats

Asked: Apr 5 '16

Seen: 302 times

Last updated: Apr 06 '16