How to optimize the parameters using libsvm?

5 visualizaciones (últimos 30 días)
Stef
Stef el 18 de Jul. de 2018
Respondida: Viren Gupta el 2 de Ag. de 2018
Libsvm FAQ suggests this piece of code:
bestcv = 0;
for log2c = -1:3,
for log2g = -4:1,
cmd = ['-v 5 -c ', num2str(2^log2c), ' -g ', num2str(2^log2g)];
cv = svmtrain(heart_scale_label, heart_scale_inst, cmd);
if (cv >= bestcv),
bestcv = cv; bestc = 2^log2c; bestg = 2^log2g;
end
fprintf('%g %g %g (best c=%g, g=%g, rate=%g)\n', log2c, log2g, cv, bestc, bestg, bestcv);
end
end
Which works perfectly fine as long as crossvalidation is included. However, I need to do the crossvalidation manually, because I need to artificially create data for the undersampled class I only want to have in the training set. But if I remove the crossvalidation, then the result is a struct which cannot be compared in the if statement. Does anybody know how to manipulate the code to make it work or how to do it differently?

Respuesta aceptada

Viren Gupta
Viren Gupta el 2 de Ag. de 2018
Firstly MATLAB does not support svmtrain with cmd parameter as suggested here.
svmtrain function returns a SVMStruct in MATLAB. SVMStruct is the trained svm model. You can use svmclassify to test your model on the test data and then calculate accuracy from the predicted test labels. The accuracy calculated can then be compared with the bestcv(as done in the if condition) to cross validate.

Más respuestas (0)

Categorías

Más información sobre Agriculture en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by