Crossvalidation for linear support vector machine
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi
I have the following code which performs k-fold crossvalidation. And as you can see the kernel chosen is a linear kernel. However, what I want to do is to perform gridsearch for the parameter C - how is that done in Matlab? Would you use standard gridsearch method as an outer loop on the k-fold crossvalidation or is there a gridsearch function specific for SVMs (I did not find any). Does anyone have me example code?
This is my code so far:
load feature
load class
k = 4; %number of folds
cvFolds = crossvalind('Kfold', class, k);
cp = classperf(class);
for i = 1:k %# for each fold
testIdx = (cvFolds == i); %# get indices of test instances
trainIdx = ~testIdx; %# get indices training instances
%# train an SVM model for autistic vs TD, k-fold crossvalidatio
svmModel = svmtrain(feature(trainIdx,:), class(trainIdx), ...
'Autoscale',true, 'Showplot',false, 'Method','QP', ...
'BoxConstraint',0.2, 'Kernel_Function','linear');
%# test using test instances
pred = svmclassify(svmModel, feature(testIdx,:), 'Showplot',false);
%# evaluate and update performance object
cp = classperf(cp, pred, testIdx);
end
%# get accuracy
cp.CorrectRate
%# get confusion matrix
%# columns:actual, rows:predicted, last-row: unclassified instances
cp.CountingMatrix
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Statistics and Machine Learning Toolbox 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!