svmtrain function is returning a zero value when used in cross validation in libsvm

I am a student with a little basics in programming. But I had written a code in matlab for support vector regression using libsvm library and in it I am using cross validation for parameter optimization. But when I am running the code its returning a zero value for "svmtrain" function which is used in the cross validation part. I cant find any error in syntax but still the error is there. Please help me with this.
I am giving my code here. Please respond....
%Reading Input and Output Files
label = xlsread('label.xlsx');
instance = xlsread('instance.xlsx');
%Dividing Data for training and testing
train_label = label(1:76,:);
test_label = label(77:108,:);
train_instance = instance(1:76,:);
test_instance = instance(77:108,:);
%Cross Validation Search for finding best parameters
bestcv =0;
bestc=0;
bestg=0;
for log2c = -6:1:6,
for log2g = -6:1:6,
cmd = [' -v 4 -c ', num2str(2^log2c), ' -g ', num2str(2^log2g)];
cv = svmtrain(train_label, train_instance, cmd)
if (cv >= bestcv),
bestcv = cv;
bestc = 2^log2c;
bestg = 2^log2g;
end
fprintf('%g %g %g (best c=%g, g=%g, rate=%g)\n', log2c, log2g, cv, bestc, bestg, bestcv);
end
end
%Training the data set
options = ['-s 3 -t 2 -c ', num2str(bestc), ' -g ', num2str(bestg), '-p' 0.1, '-h' 0'];
model = svmtrain(train_label, train_instance, options);
%Testing the data set
[predicted_trainmodel, accuracy, decision_values] = svmpredict(train_label, train_instance, model);
[predicted_testmodel, accuracy, decision_values] = svmpredict(test_label, test_instance, model);

Answers (0)

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Asked:

on 22 Mar 2016

Edited:

on 22 Mar 2016

Community Treasure Hunt

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

Start Hunting!