Reputation: 367
I am using libsvm in MATLAB to do binary classification.
I was doing cross validation with different parameters but all parameters seem to give me the same accuracy and results.
Also I am getting number of support vectors as zero for all my parameters.
Here is what I tried:
folds = 5;
[C,gam] = meshgrid(-5:2:15, -15:2:3);
cv_acc = zeros(numel(C),1);
for ii = 1:numel(C)
cv_acc(ii) = svmtrain(class, data, ...
sprintf('-c %f -g %f -v %d ',...
2^C(ii), 2^gam(ii), folds)
);
end
But I'm getting the same result for all my iterations and parameter values, which look as follows:
optimization finished, #iter = 1
nu = -1.#IND00
obj = -1.#IND00, rho = -1.#IND00
nSV = 0, nBSV = 0
Total nSV = 0
I can't find out the error with my code. Any help will be deeply appreciated.
Upvotes: 2
Views: 249
Reputation: 315
Looks like you have a problem with your data. Compare your code with this example:
%% Preparing data
load('fisheriris.mat');
[class,~,classValue] = grp2idx(species);
[data, dataMu, dataSigma] = zscore(meas);
%% Cost-Gamma optimization preparation
folds = 5;
[C,gam] = meshgrid(-5:2:15, -15:2:3);
cv_acc = cell(size(C));
%% Actual performance estimation
for ii = 1:numel(C)
cv_acc{ii} = svmtrain(classIndex, data, ...
sprintf('-c %f -g %f -v %d ',...
pow2(C(ii)), pow2(gam(ii)), folds) );
end
%% Results displaying
cv_acc_mat = cellfun(@(x) sum(x(:)==classIndex(:))/numel(x), cv_acc);
figure;
surf(unique(C), unique(gam), cv_acc_mat);
xlabel('log(Cost)');
ylabel('log(Gamma)');
zlabel('Accuracy');
Upvotes: 1