Problems after addpath libsvm library in matlab

I want to know how libsvm works. I tried this code in this link [1]: 10x cross-validation in SVN with one and against all (using LibSVM) . It works (I did not add the libsvm library path to matlab), but after adding the libsvm library. this does not work. I have no idea how to solve it. there is an error:

Error using svmtrain (line 233) Y must be a vector or a character array. Error in libsvmtrain_ova (line 11) models{k} = svmtrain(double(y==labels(k)), X, strcat(opts,' -b 1 -q')); Error in libsvmcrossval_ova (line 10) mdl = libsvmtrain_ova(y(trainIdx), X(trainIdx,:), opts); Error in main (line 9) acc = libsvmcrossval_ova(labels, data, opts, nfold); 

Anyone help me how to solve it? thanks

+6
source share
2 answers

I followed the message you referred to and I got the results without errors. For me, the cross-check accuracy for the fisheriris dataset is 96.6667%. For you, I think the error is that the error is related to "svmtrain", as the first comment said. Below I will show how I ran the code.

1) download libsvm from http://www.csie.ntu.edu.tw/~cjlin/libsvm/ and unzip it.

2) change the file names svmtrain.c and svmpredict.c in \libsvm-3.16\matlab\ as libsvmtrain.c and libsvmpredict.c . And then find make.m in the same folder and change line 16 and line 17 to

 mex CFLAGS="\$CFLAGS -std=c99" -largeArrayDims libsvmtrain.c ../svm.cpp svm_model_matlab.c mex CFLAGS="\$CFLAGS -std=c99" -largeArrayDims libsvmpredict.c ../svm.cpp svm_model_matlab.c 

3) run make.m, you just replaced the mex * .c files.

4) in accordance with the accepted response to the 10-fold cross-validation message in one-on-all SVM (using LibSVM) , you create four .m files for each function, crossvalidation.m , libsvmcrossval_ova.m , libsvmpredict_ova.m , libsvmtrain_ova.m and perform the main function provided by this answering machine, which is as follows:

 clear;clc; %# laod dataset S = load('fisheriris'); data = zscore(S.meas); labels = grp2idx(S.species); %# cross-validate using one-vs-all approach opts = '-s 0 -t 2 -c 1 -g 0.25'; %# libsvm training options nfold = 10; acc = libsvmcrossval_ova(labels, data, opts, nfold); fprintf('Cross Validation Accuracy = %.4f%%\n', 100*mean(acc)); %# compute final model over the entire dataset mdl = libsvmtrain_ova(labels, data, opts); acc = libsvmtrain(labels, data, sprintf('%s -v %d -q',opts,nfold)); model = libsvmtrain(labels, data, strcat(opts,' -q')); 
+8
source

There is a very simple way. Set the libsvm folder as the priority path in the Set Path button in your matlab.

+3
source

All Articles