你好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
吗?我该如何解决这个问题?
答案 0 :(得分:0)
我猜测cv
永远不会超过bestcv
。为了帮助调试它,你可以这样做:
bestc = []; bestg = [];
然后检查它们是否为isempty
。