SVM 训练时间是否取决于输入数据的内容?

Does SVM training time depend on content of input data?

本文关键字:数据 输入 取决于 时间 是否 SVM      更新时间:2023-10-16

我正在训练SVM(来自openCV的train_auto(两次。

两次我都使用相同的参数: C=0.01,100.000 次迭代,32 个特征和 24550 个样本。 但是不同的输入样本。第一次我只使用我的训练数据,第二次,更少的训练数据 + 一些错误的否定,但训练数据的数量与第一步相同。

第一次训练在大约 2 小时后完成。而第二个运行无休止(超过 10 小时(。这怎么可能,我该如何解决问题?

问候 斯特菲

编辑一些代码:

void SVMtrain(bool retraining) {
int factor_pos = 5;
int factor_neg = 10;
std::string line;
int N_pos = 2474;
N_pos *= factor_pos;
int N_neg = 0;
std::ifstream myfile2(LIST_NEG);
while (std::getline(myfile2, line))
++N_neg;
N_neg *= factor_neg;
Mat points = createFirstSet(N_pos, N_neg, factor_pos, factor_neg);
Mat labels = createFirstLabels(N_pos, N_neg);
Mat all_neg;
if (retraining) {
Mat hardNegatives = find_hardNegatives();
hardNegatives.copyTo(points(Rect(0, points.rows - (MAX_HARD_NEG+1), hardNegatives.cols, hardNegatives.rows)));
}
// Train with SVM
CvSVMParams params;
params.svm_type = CvSVM::C_SVC;
params.kernel_type = CvSVM::LINEAR;
params.C = 0.01; //best option according to Dalal and Triggs
params.term_crit = cvTermCriteria(CV_TERMCRIT_ITER, iterations, 1e-6);

CvSVM SVM;
if (retraining) {
cout << "Training SVM with " << points.rows << " Datapoints... (" << N_pos << ", " << points.rows - N_pos << ") since: " << getTimeFormatted()<< endl;
SVM.train_auto(points, labels, Mat(), Mat(), params);
SVM.save(SVM_2_LOCATION);
}
else {
cout << "Training SVM with " << points.rows << " Datapoints... (" << N_pos << ", " << N_neg << ") since: " << getTimeFormatted() << endl;
SVM.train_auto(points, labels, Mat(), Mat(), params);
SVM.save(SVM_LOCATION);
}
cout << "finished training at " << getTimeFormatted() << endl << endl;
}

这应该是不可能的。

但是你提到,在第二次训练中,你添加了一些假阴性。虽然我不知道你的数据到底是什么样子的,但我假设,这使得数据不是线性可分的。这可能是破坏了您对 SVM 的实现。否则我无法进一步帮助您