Simple SVM classification code
2 次查看(过去 30 天)
显示 更早的评论
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
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
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 Center 和 File Exchange 中查找有关 Naive Bayes 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!