Question

My data matrix is a 1000x65K matrix that contains 500 positive examples and 500 negative examples. My features are binary (0 or 1). My labels are [ones(500,1); -ones(500,1)];

I'm training a linear svm using the following code:

ost = 0.1;
epsilon = 2;
gamma = 0.1;
degree = 3;
coef0 = 0;

options_string = ['-s 0 -t 0 ' ' -c ' num2str(cost) ' -p ' num2str(epsilon) ' -g ' num2str(gamma) ' -d ' num2str(degree) ' -r ' num2str(coef0) ' -b 1'];
SVRModel = svm_train(data, labels , options_string);

I'm calculating the coefficients vector w using the following code:

w = zeros(1,M);
for i=1:length(SVRModel.sv_coef)
    w = w + SVRModel.sv_coef(i)*SVRModel.SVs(i,:);
end

However, all the values of the resulting vector w are the same. Also, I'm getting 484 support vectors and all the first 424 svm coefficients are 0.1 and the rest of them (also 424) are -0.1.

How can that be? Can someone please shed some light on my problem?

Thanks,

Gil.

Was it helpful?

Solution

First, you don't need gamma and coef0 in linear SVM.

Secondly, I think it should be

SVRModel = svm_train(labels, data, options_string);

in your training process.

And you can vectorize the weight and bias terms.

w = model.SVs' * model.sv_coef;
b = -model.rho;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top