windows下使用libsvm
在http://www.csie.ntu.edu.tw/~cjlin/下载libsvm-2.84;gridregression.py
在python的主页http://www.python.org上下载python-2.5
gridregression.py中用到了绘图工具gnuplot,需要下载一个gnuplot软件,地址:ftp://ftp.gnuplot.info/pub/gnuplot/(win32版本)
样本数据指定格式:[label] [index1]:[value1] [index2]:[value2] ……
(1)svmscale.exe的用法:
svmscale.exe [-1 lower] [-u upper] [-y y_lower y_upper] [-s save_filename] [-r restore_filename] filename
(2)svmtrtrain.exe训练模型:
svmtrain.exe -s 3 -t 2 -c 200 -p 0.0001 -g 0.1 grain_scale>train.txt(最好)
其中,用gridregression.py搜索最优参数的方法如下:
Usage: grid.py [-log2c begin,end,step] [-log2g begin,end,step] [-log2p begin,end,step] [-v fold]
[-svmtrain pathname] [-gnuplot pathname] [-out pathname] [-png pathname]
[additional parameters for svm-train] dataset
eg:
C:\libsvm-2.84\python>C:\Python25\python.exe gridregression.py -svmtrain C:\libsvm-2.84\windows\svmtrain.exe -gnuplot
C:\libsvm-2.84\windows\gnuplot\pgnuplot.exe -log2c 10,1000,10 -log2g 0.01,1.0,0.01 -log2p 0,0.1,0.001 -v 10 -s 3 -t 2
C:\libsvm-2.84\windows\grain_scale>gridregression_feature.parameter
(3)用svmpredict.exe进行预测
svmpredict.exe Tgrain_scale grain_scale.model T_predict>predicted.txt
其中feature_test.scaled是归一化后的测试特征文件名,feature.scaled.model是训练好的模型,SVM预测的值在feature_test.predicted中。

您当前的位置: