Ask Your Question

I cannot train data using knn

asked 2016-04-05 12:02:24 -0500

bob409 gravatar image

updated 2016-04-06 01:54:29 -0500

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.reshape(1, 1);


             Ptr<ml::KNearest> knn = ml::KNearest::create();
        Ptr<ml::TrainData> td = ml::TrainData::create(feature, ml::ROW_SAMPLE, label);  <-----I am getting error here
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-04-05 13:50:44 -0500

berak gravatar image

updated 2016-04-05 13:55:11 -0500

  • 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.
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-04-05 12:02:24 -0500

Seen: 139 times

Last updated: Apr 06 '16