libsvm使用教程

来源:互联网 发布:京东商城与淘宝的区别 编辑:程序博客网 时间:2024/05/16 19:46

libsvm使用教程

  最近在使用libsvm实现论文中的一些算法,libsvm官网给出了一篇全英文的教程,但是我感觉介绍的不够全面,在网上也没有搜到能详细介绍libsvm的中文博客,于是决定自己写一篇博文,全面介绍libsvm,这篇博文会一直不定时更新,直到形成一篇最完整的libsvm教程。

  • svm核函数
  • libsvm参数
  • SVM松弛变量和惩罚因子
  • SVM公式
  • Example

svm核函数

以下是几种常用的核函数表示:
线性核(Linear Kernel):

k(x,y)=xTy+c

多项式核(Polynomial Kernel)
k(x,y)=(axTy+c)d

径向基核函数(Radial Basis Function)
k(x,y)=exp(γxy2)

Sigmoid核(Sigmoid Kernel)
k(x,y)=tanh(axT+c)

核函数更多详细细节,请参见SVM核函数。


libsvm参数

options:
-s svm_type : 设置选用SVM的类型 (default 0)
  0 – C-SVC( support vector classification (two-class and multi-class))
  1 – nu-SVC
  2 – one-class SVM
  3 – epsilon-SVR( support vector regression)
  4 – nu-SVR
注意:C_SVC与NU_SVC其实采用的模型相同,但是它们的参数C的范围不同,C_SVC采用的是0到正无穷,NU_SVC是[0,1]。

-t kernel_type : 设置选用核函数的类型 (default 2)
  0 – linear u’v
  1 – polynomial (r*u’v + coef0)^degree
  2 – radial basis function(RBF) exp(-gamma|u-v|^2)
  3 – sigmoid tanh(r*u’v + coef0)
-d degree : 核函数中的degree设置(针对多项式核函数)(默认3)(default 3)
-g r(gamma):核函数中的gamma函数设置(针对多项式/rbf/sigmoid核函数)(default 1/num_features)
-r coef0:核函数中的coef0设置(针对多项式/sigmoid核函数)(default 0)
-c cost:设置C-SVC,e -SVR和v-SVR的参数(损失函数) (default 1)
-n nu:设置nu-SVC,一类SVM和nu- SVR的参数(默认0.5) (default 0.5)
-p p:设置e -SVR 中损失函数p的值(default 0.1)
-m cachesize : set cache memory size in MB (default 100)
-e epsilon : 设置允许的终止判据 (default 0.001)
-h shrinking:是否使用启发式,0或1(默认1)
-b probability_estimates: whether to train a SVC or SVR model for probability estimates, 0 or 1 (default 0)
-wi weight: set the parameter C of class i to weight*C, for C-SVC (default 1)
(-wi weight 可以将类别号为 i 的这个类别的惩罚参数变为weight*C,比如测试数据有两类,标签分别为1 -1 如果之前设置了c=14,此时再用 -w1 0.5 -w-1 10 参数设置 则此时标签为1的这类的惩罚参数变为0.5*14 = 7,标签为-1的这类的惩罚参数变为10*14 = 140)


SVM松弛变量和惩罚因子

参考博文:松弛变量与惩罚因子和理解SVM三层境界中关于松弛变量的介绍


SVM公式

  这一部分给出了不同类型SVM(C-SVC、nu-SVC、nu-SVR等)所对应的具体公式。

C-SVC

这里写图片描述


Example

0 0
原创粉丝点击