嗨stackoverflow世界,
所以我试图通过 svm 训练模型运行一些数据,我遇到了以下错误:
Undefined function or variable 'bestc'.
Error in train_svm_model_sh (line 28)
cmd = ['-s 0 -t 0 -c', num2str(bestc), '-g', num2str(bestg)];
我的原始脚本在哪里:
bestcv = 0;
for log2c = -10:10,
for log2g = -10:10,
cmd = ['-s 0 -t 0 -v 20 -c', num2str(2^log2c), '-g', num2str(2^log2g) '-q'];
cv = svmtrain(labels, data, cmd);
if (cv > bestcv),
bestcv = cv; bestc = 2^log2c; bestg = 2^log2g;
fprintf('%g %g %g (best c = %g, g = %g, rate = %g)\n', log2c, log2g, cv, bestc, bestg, bestcv);
end
end
end
cmd = ['-s 0 -t 0 -c', num2str(bestc), '-g', num2str(bestg)];
运行有问题的线路是:
cmd = ['-s 0 -t 0 -c', num2str(bestc), '-g', num2str(bestg)];
这是因为我只在 if 循环中bestc
定义了变量吗?bestg
我该如何解决这个问题?