3.2.0 SVM OpenCV Error: Assertion failed (samples.cols == var_count && samples.type() == CV_32F) in predict, file C:/repo/mingw-w64-opencv/src/opencv-3.2.0/modules/ml/src/svm.cpp, line 1930

asked 2017-05-02 04:36:58 -0600

eipoa gravatar image

OpenCV Error: Assertion failed (samples.cols == var_count && samples.type() == CV_32F) in predict, file C:/repo/mingw-w64-opencv/src/opencv-3.2.0/modules/ml/src/svm.cpp, line 1930

vector<int> Idx {1,2,3,4,5,6,7,8,9,10,11,13};//0,1,2,3,4,5,6,7,8,9,10,11,12,13; (14 features)
Mat varIdx(Idx);
Ptr<TrainData> _Samples = TrainData::create(Train, ROW_SAMPLE, TrainResp, _Params.getVarIdx());
Ptr<NormalBayesClassifier> normalBayesClassifier = StatModel::train<NormalBayesClassifier>(_Samples);
normalBayesClassifier->predict(Test, results);
......
svm->trainAuto(_Samples);
svm->predict(Test, results);// error

the varidx for svm doesnot work, but for Bayes it works, at least the program doesnot crash. I checked some answers from google, someone said varidx should be like this {0,1,1,1,1,0,1...}, it is so strange, i cannot believe it.

edit retag flag offensive close merge delete

Comments

if i may ask, - what do you need the varIdx for ?

also, what exactly is in your Test Mat ? if you mask out the 1st col in your train data, you probably have to do the same for the prediction later (somehow)

berak gravatar imageberak ( 2017-05-03 01:25:34 -0600 )edit

I want to test which combinations of features are more important. the varidx works when using bayes classifier. i thing they shuld be the same cause they are all the children of StatModel. anyway, i think that maybe after useing setTrainTestSplitRatio() to divied data into train and test, the varidx may work well. but unfortunately, after this it doesn't work when i call pridect(). i mean the following the steps donot work at all. 1. setTrainTestSplitRatio 2. train 3. predict i forgot the error message, it seems that data type error., but after spliting, no way to change data type. i donot know whether the ml pass the test.

eipoa gravatar imageeipoa ( 2017-05-04 09:23:49 -0600 )edit