Hi stackoverflow world,
So I am attempting to run some data through an svm train model and I am running into the following error:
Undefined function or variable 'bestc'.
Error in train_svm_model_sh (line 28)
cmd = ['-s 0 -t 0 -c', num2str(bestc), '-g', num2str(bestg)];
Where my original script was:
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)];
And the line having an issue running is:
cmd = ['-s 0 -t 0 -c', num2str(bestc), '-g', num2str(bestg)];
Is this because I've only defined the variables bestc
and bestg
in the if loop? How do I solve this?
I'm guessing that cv
is never greater than bestcv
. To help debug it you could do:
bestc = []; bestg = [];
and then check to see if they are isempty
.