我正在尝试使用函数trainAuto交叉验证我的训练数据,我得到错误::: OpenCV错误:错误的参数(虽然交叉验证一个或多个类已经从样本中删除。尝试减少do_train。
当我改变trainAuto功能只是训练它有效,但我需要trainauto。我需要验证我拥有的每个数据点,即70分。我想要做的是交叉验证我的trainingData数组中的每一点。我的所有数据点和标签都存储在我的标签[70]和trainingData [70] [2744]数组中。当我试图交叉验证我的训练数据时,我复制了trainingData [70] [2744]中的每一行,除了应该测试的那一行,那一行被复制到testData数组。这应该做70次,所以70次测试。这是我的代码,任何帮助将不胜感激。
//my labels and points are stored here
int labels[70] = {};
float trainingData[70][2744] = {};
//this is where the copy of my test, labels and training data should end up for the cross validation
int labelstrain[69] = {};
float trainingDatatrain[69][2744] = {};
float testData[2744] = {};
//looping through everything and extracting test point, labels for the points and training data
for(int o = 0; o < 70; ++o){
memcpy(testData, trainingData[o], sizeof(testData));
for(int p = 0; p < 70; p++){
if(o != p){
labelstrain[p] = labels[p];
copy(trainingData[p], trainingData[p] + 2744, trainingDatatrain[p]);
}
else{
cout << "label that was left out: " <<labels[p]<< endl;
}
}
//creating matrix of my labels, test point and training data
Mat labelsMat(69, 1, CV_32SC1, labelstrain);
Mat trainingDataMat(69, 2744, CV_32FC1, trainingDatatrain);
Mat testDataMat(1, 2744, CV_32FC1, testData);
//here is my problem where i get a error. Only train here works fine
svmLin->trainAuto(ml::TrainData::create(trainingDataMat, ml::ROW_SAMPLE, labelsMat));
svmPoly->trainAuto(ml::TrainData::create(trainingDataMat, ml::ROW_SAMPLE, labelsMat));
svmRbf->trainAuto(ml::TrainData::create(trainingDataMat, ml::ROW_SAMPLE, labelsMat));
svmSig->trainAuto(ml::TrainData::create(trainingDataMat, ml::ROW_SAMPLE, labelsMat));
svmChi2->trainAuto(ml::TrainData::create(trainingDataMat, ml::ROW_SAMPLE, labelsMat));
svmInter->trainAuto(ml::TrainData::create(trainingDataMat, ml::ROW_SAMPLE, labelsMat));
//predicting on my point that is not in my trainingdata
float predictLin = svmLin->predict(testDataMat);
float predictPoly = svmPoly->predict(testDataMat);
float predictRbf = svmRbf->predict(testDataMat);
float predictSig = svmSig->predict(testDataMat);
float predictChi2 = svmChi2->predict(testDataMat);
float predictInter = svmInter->predict(testDataMat);
}