How to optimize the parameters using libsvm?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Stef
le 18 Juil 2018
Réponse apportée : Viren Gupta
le 2 Août 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?
0 commentaires
Réponse acceptée
Viren Gupta
le 2 Août 2018
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.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Particle Swarm dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!