简体   繁体   English

在Visual Studio 2010上使用LIBSVM

[英]Using LIBSVM on Visual studio 2010

I wanted to use libsvm in visual studio 2010 just for classifying my test sample and nothing more .. 我想在Visual Studio 2010中使用libsvm只是为了对测试样本进行分类,仅此而已。

I've worked with libsvm using the documentation provided by its official site ... 我已经使用libsvm的官方网站提供的文档来工作...

So I used these steps sequentially 所以我按顺序使用了这些步骤

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

2). 2)。 svm-scale -r range test.txt> test.scale svm-scale -r范围test.txt> test.scale

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

4). 4)。 svm-train -c 32 -g 0.05 -b 1 train.scale train.model svm-train -c 32 -g 0.05 -b 1火车规模火车模型

5). 5)。 svm-predict test.scale train.model test.out 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 : 而且效果很好,但是问题是我不知道如何在Visual Studio中执行这些步骤……我只是从上面加载了train.model(第4步),并且没有在VS10中重复训练过程....这是我的代码:

  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%!!!! 但这不是python代码的结果,在python中,我的测试数据的精度为98%,但在这里不到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. 我还使用OPENCV训练数据并测试样品(使用ml.h),但在OPENCV中,我的准确率达到了70%。 and it's still more than 20% reduction from my real result !!!! 仍然比我的实际结果减少了20%以上!

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 ..... 我认为问题在于缩放..因为在svm.h和OPENCV中我都没有找到任何缩放我的训练和测试数据的功能.....

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. 只需从http://www.csie.ntu.edu.tw/~cjlin/libsvm/获取libsvm的源代码,然后将svm-scale.c中的缩放恢复逻辑合并到您的代码中。 To see where the scaling paramters are read in, search for: 要查看在哪里读取缩放参数,请搜索:

    if(restore_filename)

The actual scaling is done in a function called output(). 实际缩放是在称为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). 顺便说一句,opencv中的libsvm版本比较旧(因此避免使用)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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