gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-27 23:52:55 24 4
gpt4 key购买 nike

我正在训练 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 的实现。否则我帮不了你了

关于c++ - SVM 训练时间是否取决于输入数据的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45000354/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com