Opencv SVM一类预测始终返回0

时间:2019-06-22 08:12:44

标签: c++ opencv svm one-class-classification

我正在处理SVM和一类分类问题。数据是一个nx3矩阵,其中每一行都是一个样本,因此我在数据矩阵中有n个样本:

0.012873813, 0.094377473, 0.0043269233
0.020184161, 0.10070252,  0.0045584044
0.023954002, 0.10439565,  0.0045248871
0.024797738, 0.11338359,  0.0043057571
0.02122326,  0.106646,    0.0043315911
0.019649299, 0.10178889,  0.0043589743
0.01888592,  0.10269108,  0.0041237115
0.016681647, 0.10080954,  0.0042823157
0.033328395, 0.12347542,  0.0047008549
0.025292512, 0.11120763,  0.0049382718
0.028693195, 0.12776338,  0.0038888888
0.022229074, 0.10848146,  0.0042232275
0.022953529, 0.1088412,   0.0043237805
0.016452817, 0.096003316, 0.004687069
0.025636395, 0.12612548,  0.0039009422
0.02329725,  0.11335891,  0.0044992748
0.019382631, 0.10725249,  0.0045421249
0.026173679, 0.11711644,  0.0041491836

我为训练数据编写的代码如下:

cv::Ptr<cv::ml::SVM> model;
model = cv::ml::SVM::create();
model->setType(SVM::ONE_CLASS);
model->setC(5.00);
model->setKernel(SVM::RBF);
model->setGamma(.000020);
model->setNu(0.025);
model->setDegree(3);
model->setCoef0(0);
model->setP(0);

cv::Mat responses = cv::Mat::ones(samples.rows, 1, CV_32SC1); // Also tried with CV_32F
model->setTermCriteria(cv::TermCriteria(cv::TermCriteria::MAX_ITER, (int)1e7, 1e-6));
model->train(samples, cv::ml::ROW_SAMPLE, responses);

当我通过以下方式做出预测时:

model->predict(samples, responses);

它总是返回零的nx1向量作为响应。

0 个答案:

没有答案