escorciav
escorciav

Reputation: 85

Compute objective value LIBSVM Matlab

I'm training an SVM inside a for loop changing the features of my instances and I would like to plot the final objective value vs iteration. I'm using LIBSVM in Matlab but I don't find explicitly the final objective value in the returned model. How do I compute the final objective value with the returned model in each interation?

It's possible read the script printed by the svmtrain but I'd like to compute this value without this trick.

P.D. I have a basic knowledge of C++.

Upvotes: 0

Views: 1152

Answers (1)

escorciav
escorciav

Reputation: 85

I modify the svm.cpp and svm.h to return the objective value adding a few lines of code.

1) Add new field in the svmmodel (svm.h) and decision_function (svm.cpp) structures.

2) Copy the si.obj in the new field of the decision_function.

3) Copy the field catch by the decision_function into the newer field of the svmmodel structure (svm_train function in the svm.cpp).

4) Modify the svm_model_matlab.c to admit the new field in the svmmodel structure.

  • Incremet the NUMBER_OF_FIELD variable and add a new field in the output structure.
  • According to the order in the output structure modify the function model_to_matlab_struct. (It's easy copy the code used for the field rho and replace rho by your variable's name)
  • Modify the matrix_matlab_to_model function

It's really easy and straighforward.

I can pass the new files only send me an email with the purpose: LIBSVM-ObjModification

Upvotes: 1

Related Questions