Eliya
Eliya

Reputation: 165

LIBSVM SVM in octave - how to use myself (without "svmpredict" ) with the parameter that return from "svmtrain"

Hi i have a previous background in ANN (Artificial Neural Network), and i did it with octave. i succeeded to converted the network from octave to c++.

the way i did it is to look on the parameter that return from network (wight matrix, and bias matrix) and copy it to c++ parameter and doing the correct calculation.

Now i start to work with svm in octave, with LIBSVM i succeeded to train

here the code to train:

model = svmtrain(vOutput, vInput,'-g 1 -c 100 ' ); 

and as well to predict the result for validation group (new group) here the code for predict:

[predicted_label, accuracy, dec_values] = svmpredict(targetHit', inputHit, model); 

it's work well.. but i need to do it with c++ so i want to understand how to predict the result myself without using svmpredict build function.

The parameters i got after train is:

fieldnames(model)
ans =
{
  [1,1] = Parameters
  [2,1] = nr_class
  [3,1] = totalSV
  [4,1] = rho
  [5,1] = Label
  [6,1] = sv_indices
  [7,1] = ProbA
  [8,1] = ProbB
  [9,1] = nSV
  [10,1] = sv_coef
  [11,1] = SVs
} 

but i don't know how to use with this parameters. If anyone can help me and explain me how to use with the parameters by hand without using svmpredict function.

O.k i find this code :

w = (model.sv_coef' * full(model.SVs));
bias = -model.rho;
predictions = sign(inputMiss * w' + bias);

But it doesn't compatible to result from svmpredict..

Upvotes: 1

Views: 708

Answers (1)

Yosef Alon
Yosef Alon

Reputation: 78

This code should help you:

w = (model.sv_coef' * full(model.SVs));
bias = -model.rho;
predictions = sign(inputMiss * w' + bias);

But it doesn't compatible to result from svmpredict -> It should Fit(Check Again.

Upvotes: 1

Related Questions