Simple SVM classification code

1 visualización (últimos 30 días)
MiauMiau
MiauMiau el 15 de Sept. de 2015
Comentada: Vania krm el 21 de Mayo de 2019
Hi,
I have Matlab2013a, and use the following code for classifying my data (it is mostly taken from http://stackoverflow.com/questions/3070789/example-of-10-fold-svm-classification-in-matlab). My feature matrix is 84x19900 (84 subjects, each subjects having a row vector with 19 900 features), and class is a 84x1 logical array (1-42 are 1s, 42-84 are 0s). Yet my code throws an error (see end):
load feature load class
k = 7; %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 over training instances
svmModel = svmtrain(feature(trainIdx,:), class(trainIdx), ...
'Autoscale',true, 'Showplot',false, 'Method','QP', ...
'BoxConstraint',2e-1, 'Kernel_Function','rbf', 'RBF_Sigma',1);
%# 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
Error:
Error using svmclassify (line 53)
The first input should be a struct generated by SVMTRAIN.
Error in classifyAutismTD (line 18)
pred = svmclassify(svmModel, feature(testIdx,:), 'Showplot',false);
What is wrong?
  4 comentarios
the cyclist
the cyclist el 15 de Sept. de 2015
You might consider copying this last comment of yours into an answer, and then accepting it. This might help other people in the future with a similar problem.
Vania krm
Vania krm el 21 de Mayo de 2019
Dear @MiauMiau
I have also this error and I can not solve it. Can you explain more how I can check the libsvm folder?

Iniciar sesión para comentar.

Respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by