Dumping Cross-Validation Result out from libsvm

by Forrest Sheng Bao http://fsbao.net

Libsvm (http://www.csie.ntu.edu.tw/~cjlin/libsvm/) is a great SVM implementation, made by a group in National Taiwan University, Taiwan.

But you can't see the cross-validation result, by default. Now I am gonna do a multi-source boosting and I am gonna compute the sensitivity and specificity. So I need the result of each weak classifier.

What to do? Well, libsvm is open sourced! You just need to simply modify the svm-train.c file. Following discussion is based on libsvm v. 2.88, released on Oct. 30, 2008

If you could understand the diff tool, here is the result of running

diff svm-train.c svm-train.origin.c 
You can see my modifications are marked as "modified by Forrest"
<> void do_cross_validation();
<> do_cross_validation();
<> void do_cross_validation()
< //modified by Forrest < dumpfile=" fopen(filename," accuracy =" %g%%\n"> printf("Cross Validation Accuracy = %g%%\n",100.0*total_correct/prob.l);

The result is stored in the array target but the actual target is stored in the array prob.y. So I dump these two arrays as two columns into a file. The dumping file shares the same prefix with the input file (for cross-validation there is only one input file of svmlight format) but with a ".dump" extension. So, the do_cross_validationchar *filename this time. In line 70, you can feed in the filename by a global variable input_file_name which is obtained by the function parse_command_line. should have an input argument

That's why we should open source software for research - you can always make tools work in the way you want. Now I am gonna write another program to read the result from the dumping file and do classifier boosting.

No comments: