Simple SVM classification code

1 次查看(过去 30 天)
MiauMiau
MiauMiau 2015-9-15
评论: Vania krm 2019-5-21
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 个评论
the cyclist
the cyclist 2015-9-15
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 2019-5-21
Dear @MiauMiau
I have also this error and I can not solve it. Can you explain more how I can check the libsvm folder?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Classification Ensembles 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by