简体   繁体   中英

Using LIBSVM on Visual studio 2010

I wanted to use libsvm in visual studio 2010 just for classifying my test sample and nothing more ..

I've worked with libsvm using the documentation provided by its official site ...

So I used these steps sequentially

1). svm-scale -l 0 -s range train.txt> train.scale

2). svm-scale -r range test.txt> test.scale

3). grid.py -svm-train "MYSVM_TRAIN_PATH" -gnuplot "MY_GNUPLOT_PATH" train.scale

4). svm-train -c 32 -g 0.05 -b 1 train.scale train.model

5). svm-predict test.scale train.model test.out

and it worked pretty well , but the problem is that I don't know how to do these steps in visual studio ... I just loaded my train.model (step 4) from above, and did not repeat the training procedure in VS10 .... here it's my code :

  void main(){ svm_model *Model; Model = svm_load_model("train.model");//loaded from svm-train (step4 above) svm_node x[feature_size]; (Some internal Process for obtaining new feature vector for testing) double result = svm_predict(Model,x); std::cout<<"result is"<<result<<std::endl; return 0} 

but this does not result as python code , in python I get 98% precision for my test data but in here it's less than 20%!!!! it's somehow aweful ...

I also used OPENCV for training my data and testing my samples (Using ml.h) but in OPENCV ,I got 70 % accuracy. and it's still more than 20% reduction from my real result !!!!

I think the problem is in the scaling .. because in both svm.h and OPENCV I didn't find any function for scaling my train and test data .....

Your usage of the command line tools looks ok. If you don't scale your test data the same way as your training data then predict will fail as you have discovered.

Just get the source for libsvm from http://www.csie.ntu.edu.tw/~cjlin/libsvm/ and incorporate the scaling restore logic in svm-scale.c into your code. To see where the scaling paramters are read in, search for:

    if(restore_filename)

The actual scaling is done in a function called output(). It would obviously be straight forward to return a value instead of printing the result.

BTW the libsvm version in opencv is rather old (so I avoid it).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM