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