Categories: BIO, SVM | Tags: | Views: 4,460

 

最近的工作要用到支持向量机(SVM), 对算法不是很懂, 但是总要把用法弄明白吧, 于是就想把它的文档翻译一下, 自己弄明白吧, 也给其他人带来点方便

先给出libsvm的下载地址:   要下载就点我吧

英文文档请见压缩包内的 README 文件(用写字板打开就可以看到内容了)

其中, tools目录下的README的翻译在这里.


libsvm-2.88中文文档

中文文档由 pwwang 翻译, 欢迎转载, 转载请注明出处!

 

Libsvm是一个简单、易用、有效的SVM分类和回归软件。它解决了C-SVM分类、nu-SVM分类、one-class-SVM、epsilon-SVM回归和nu-SVM回归。它还为C-SVM提供了一个自动模型选择工具。这个文档将解释libsvm的用法。

Libsvm可以从这里得到:http://www.csie.ntu.edu.tw/~cjlin/libsvm
在使用libsvm之前先阅读COPYRIGHT文件。

目录
=================

-快速开始
-安装和数据格式
-“svm-train”的用法
-“svm-predict”的用法
-“svm-scale”的用法
-实际使用技巧
-例子
(后面的部分不作翻译)

 

快速开始
=================

如果你是SVM的一个新手,并且数据不大,那么在安装完成之后请打开tools目录使用easy.py。它将把一切全自动化,从数据规化到参数选择。

用法:easy.py training_file [test_file]

你可以在“tools/README”中找到关于参数选择的更多信息。

 

安装和数据格式
=================

在Unix系统中,输入make来生成“svm-train”和“svm-predict”程序。不带参数地运行它们可以显示他们的用法。

在其他系统中,参考“Makefile”来生成它们(例如:你可以参数这篇文档中的“生成Windows可执行文件”)或者使用预生成二进制文件(Windows二进制文件在”windows“目录中)

训练和测试数据文件中的格式是:

<label> <index1>:<value1> <index2>:<value2> …
.
.
.

每行包含一个实例,并且以“n”(译者注:换行符)结束。对于分类来说,<label>是一个指向该类标志的整数(支持多类)。对于回归来说,<label>是一个可为任何实数的目标值。对于one-class-SVM来说,它不会被用到,所以可以为任何数值。除非使用预先计算的核(将在另一节介绍),<index>:<value>给出了一个特性(属性)值。<index>是一个从1开始的整数,<value>是一个实数。索引必须按升序排列。标签在测试文件中只被用来计算精确度或者错误。如果它们是未知的,把第一列赋任意值。

这个包内的一个分类数据的例子是“heart_scale”。可以使用“tools/checkdata.py”来检测你数据格式是否正确。(详见“tools/README”)。

输入“svm-train heart_scale”,程序将读取训练数据并输出模型文件“hear_scale.model”。如果你有一个测试集叫“heart_scale.t”,那么输入“svm-predict heart_scale.t heart_scale.model output” 来检查预测的准确性。“output”文件包含了预测的类标签。

这个包里还有一些其他的有用的程序:

svm-scale:

规化你的输入数据文件

svm-toy:

这是一个简单的图形界面,它将在一个面板上显示SVM如果分离数据。你可以在窗口里单击来画数据点。使用“change”按钮来选择类1,2或者3(例如:一直到3个类都是支持的),“load”按钮用来从文件里装入数据,“save”按钮用来保存数据到一个文件,“run”按钮用来获取一个SVM模型,“clear”按钮用来清除窗口。

你可以窗口的底部输入选项,选项的符号规则和“svm-train”一样。

注意“load”和“save”只考虑了分类情况下的数据,而没有考虑回归的情况。每一个数据库有一个标签(颜色),它必须是1,2或者3,并且两个属性(x和y值)范围必须是[0,1]。

在各个目录中输入make来生成它们。

你需要Qt库来生成Qt版本(可以在这里得到:http://www.trolltech.com)

你需要GTK+库来生成GTK版本(可以在这里得到:http://www.gtk.org)

预生成的Windows二进制文件可“Windows”目录中。我们使用的是32-位机上的Visual C++,所以最大缓存是2GB。

 

“svm-train”的用法
=================

用法:svm-train [options] training_set_file [model_file]
选项:
-s svm_type : 设定SVM的类型 (default 0)
    0 — C-SVC
    1 — nu-SVC
    2 — one-class SVM
    3 — epsilon-SVR
    4 — nu-SVR
-t kernel_type : 设定核函数的类型 (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)
    4 — precomputed kernel (kernel values in training_set_file)
-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 100)
-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

-g中的k表示输入数据中属性的数目。

-v选项把数据随机分成n个部分,并计算它们的交叉验证accuracy/mean方差(不知道这个数学术语怎么翻译)

通过libsvm FAQ来查看输出文件的含义。

 

“svm-predict”的用法
=================

用法: svm-predict [options] test_file model_file output_file
选项:
-b probability_estimates: 是否预测概率估计, 0 或 1 (默认 0); one-class SVM只支持0

model_file是svm-train生成的model文件.
test_file 是你想预测的数据.
svm-predict 将把结果输出到output_file.

"svm-scale" Usage
=================

用法: svm-scale [options] data_filename
选项:
-l lower : x 规化的最小值 (默认 -1)
-u upper : x 规化的最大值 (默认 +1)
-y y_lower y_upper : y 规化的限定 (默认: 不规化y)
-s save_filename : 保存规化参数到 save_filename
-r restore_filename : 从restore_filename恢复规化参数

查看这个文档的’Examples’ 来获取例子。

 

实际使用技巧
=================

* 你的数据的规化。例如,规化每一个属性到[0,1]或[-1,+1]。
* 对于C-SVC,考虑使用tools目录中的模型选择工具。
* nu in nu-SVC/one-class-SVM/nu-SVR approximates the fraction of training  errors and support vectors. 
* 如果分类数据不平衡(如太多正数,极少负数),使用-wi尝试一个不同的罚分参数C。
* 为大的问题指定更大的缓存大小(如 larger -m)

Examples
========

> svm-scale -l -1 -u 1 -s range train > train.scale
> svm-scale -r range test > test.scale

Scale each feature of the training data to be in [-1,1]. Scaling factors are stored in the file range and then used for scaling the test data.

> svm-train -s 0 -c 5 -t 2 -g 0.5 -e 0.1 data_file

Train a classifier with RBF kernel exp(-0.5|u-v|^2), C=10, and stopping tolerance 0.1.

> svm-train -s 3 -p 0.1 -t 0 data_file

Solve SVM regression with linear kernel u’v and epsilon=0.1 in the loss function.

> svm-train -c 10 -w1 1 -w-1 5 data_file

Train a classifier with penalty 10 = 1 * 10 for class 1 and penalty 50 = 5 * 50 for class -1.

> svm-train -s 0 -c 100 -g 0.1 -v 5 data_file

Do five-fold cross validation for the classifier using the parameters C = 100 and gamma = 0.1

> svm-train -s 0 -b 1 data_file
> svm-predict -b 1 test_file data_file.model output_file

Obtain a model with probability information and predict test data with probability estimates

 

这篇文章来自 迷途知返(PWWANG.COM), 转载请注明出处。 版权说明

  1. Alexwebmaster
    March 4th, 2009 at 04:49
    Reply | Quote | #1

    Hello webmaster
    I would like to share with you a link to your site
    write me here preonrelt@mail.ru

1 trackbacks

;) :| :x :twisted: :roll: :oops: :o :mrgreen: :lol: :idea: :evil: :cry: :arrow: :P :D :?: :? :) :( :!: 8O 8)

你可以使用@somebody:开头, 来邮件通知somebody你回复了他的留言(用户名区分大小写).