I can not use libsvm!!!

75 ビュー (過去 30 日間)
Atieh
Atieh 2011 年 6 月 3 日
コメント済み: Najiyah Valappil 2020 年 3 月 16 日
Hi,
can anybody help me in using libsvm?
but it can not be recognized by my matlab, I got the following error:
??? Undefined function or method 'libsvmtrain' for input arguments of type 'double'.
Error in ==> svmtrts at 139 D.net.svm=libsvmtrain(otY,stX,'-t 0');
Error in ==> main at 148 [D,Dtest]=svmtrts(trndataSVM,tstdataSVM,'libsvm');
can anybody help me.
Regards, Atieh

採用された回答

Friedrich
Friedrich 2011 年 6 月 3 日
I think your are talking about:
The function libsvmtrain does not exist in that package. The training function is called svmtrain.

その他の回答 (1 件)

Jonas Reber
Jonas Reber 2011 年 6 月 3 日
I used libsvm myself in matlab.
then let me provide you my sample code - note: I use precompiled kernel data.
Here, I would like to find the optimal parameter c for my SVM.
clear all; close all;
%%load datasets
[lvtest, test] = libsvmread('test.krnl');
[lvtrain, train] = libsvmread('train.krnl');
[lvvalid, valid] = libsvmread('valid.krnl');
%%optimize parameter c on validation set
n = -17:17;
accuracy = nan(size(n));
for i=1:numel(n); % n = {-17,...,17}
c=2^n(i);
% create model
model = svmtrain(lvtrain, train,['-q -t 4 -c ' num2str(c)]);
% option: -t 4 -> precomputed kernel
[lbl, acc, dec] = svmpredict(lvvalid, valid, model);
accuracy(i) = acc(1);
end
% output the accuracy vs the chosen parameter c
plot(accuracy);
xlabel('c'), ylabel('Accuracy'); title('Accuracy vs. c');
%%test optimal c on the test set
[~, i] = max(accuracy); % find the best value
c = 2^n(i); % this is the optimal c
% create model
model = svmtrain(lvtrain, train,['-q -t 4 -c ' num2str(c)]);
% test on the testset
[lbl, acc, dec] = svmpredict(lvtest, test, model, []);
% show accuracy
disp(['Accuracy with optimized c (' ...
num2str(c) ') on Testset: ' num2str(acc(1)) '%']);
hope this helps...?
  2 件のコメント
judy  frost
judy frost 2013 年 9 月 23 日
Can you please explain the example further by showing how to find optimal cost and gamma values from validation data that are used for k-fold cross validation. Furthermore is it possible to plot the graph of classified data at the end of validation,training and test stages. I will appreciate any further explanation regarding the topic. Thank you.
Najiyah Valappil
Najiyah Valappil 2020 年 3 月 16 日
Can you plaese explain how this data was prepared?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by