libsvm(ZZ)

Libsvm软件的使用

软件安装:

1.解压缩libsvm-2.8.zip

2.安装Python(双击“python-2.4.2.msi”开始安装)

3.编辑./libsvm-2.8/tools/grid.py用UltraEdit打开,修改svmtrain_exe的路径eg:

修改前:修改后:

训练与测试:/windows目录下有四个.exe文件,其中svmscale.exe——用于输入数据的尺度化(Scaling)svmtrain.exe——用于样本训练svmpredict.exe——用于样本测试 Scaling一般在自己的程序里头直接处理,常用的是svmtrain和svmpredict。

svmtrain和svmpredict都在命令行方式下运行。

 Usage:svmtrain [options] training_set_file [model_file]

options:

-s svm_type:set type of SVM (default 0)

0 -- C-SVC

1 -- nu-SVC

2 -- one-class SVM

3 -- epsilon-SVR

4 -- nu-SVR

-t kernel_type:set type of kernel function (default 2)

0 – linear:u'*v

1 – polynomial:(gamma*u'*v + coef0)^degree

2 -- radial basis function:exp(-gamma*|u-v|^2)

3 – sigmoid:tanh(gamma*u'*v + coef0)

-d degree:set degree in kernel function (default 3)

-g gamma:set gamma in kernel function (default 1/k)

-r coef0:set coef0 in kernel function (default 0)

-c cost:set the parameter C of C-SVC, epsilon-SVR, and nu-SVR (default 1)

-n nu:set the parameter nu of nu-SVC, one-class SVM, and nu-SVR (default 0.5)

-p epsilon:set the epsilon in loss function of epsilon-SVR (default 0.1)

-m cachesize:set cache memory size in MB (default 40)

-e epsilon:set tolerance of termination criterion (default 0.001)

-h shrinking:whether to use the shrinking heuristics, 0 or 1 (default 1)

-b probability_estimates:whether to train an SVC or SVR model for probability estimates, 0 or 1 (default 0)

-wi weight:set the parameter C of class i to weight*C in C-SVC (default 1)

-v n:n-fold cross validation mode

常用的是C-SVC(RBF kernel function)

比较常用的几个参数:

-c// 惩罚因子

-g// 核函数参数

-v// n-fold Cross Validation

-wi// 分别设置两类样本的惩罚因子此例中,设置正例样本(分类结果是+1)惩罚因子为5*20=100,

负例样本惩罚因子为1*20=20。样本训练完,得到一个模型文件(hs.model)。

 Usage:svm-predict [options] test_file model_file output_file

options:

-b probability_estimates:whether to predict probability estimates, 0 or 1 (default 0);

one-class SVM not supported yet

此例中,待检验样本(heart_scale)根据已建立的模型(hs.model)产生一个输出(hs.out)。

 libsvm使用的数据格式:该软件使用的训练数据和检验数据文件格式如下: <label> <index1>:<value1> <index2>:<value2> ... 其中<label>是训练数据集的目标值,对于分类,它是标识某类的整数(支持多个类)。<index>是以1开始的整数,可以是不连续的;<value>为实数,也就是我们常说的自变量。检验数据文件中的label只用于计算准确度或误差,如果它是未知的,只需用一个数填写这一栏,也可以空着不填。

在程序包中,包括有一个训练数据实例:heart_scale,方便参考数据文件格式以及练习使用软件。

grid.py的使用:利用log2c、log2g的組合值來找參數 比较常用的几个参数:-v// 指定cross validation的方式,预设是5。-log2c// C的值:[起始值,终止值,步长]-log2g// g的值  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值