matlab中libsvm的svmtrain函数用法

这里的LIBSVM是一个由台湾大学林智仁(Lin Chih-Jen)教授等开发的SVM模式识别与回归的软件包,使用简单,功能强大,本文主要介绍其在Matlab中的使用。

注意不是matlab自带的svm实现函数,自带的svm实现函数仅支持分类问题,不支持回归问题;而libsvm不仅支持分类问题,亦支持回归问题,参数可调节,功能更强大。

libsvm的配置很简单,只需要下载高级版本的matlab和libsvm,VC或VS编译实现很简单的,这里就不细讲了。

两个步骤:训练建模——>模型预测

分类 model = svmtrain(trainlabel, traindata, ‘-s 0 -t 2 -c 1.2 -g 2.8’);

回归 model = svmtrain(trainlabel, traindata, ‘-s 3 -t 2 -c 2.2 -g 2.8 -p 0.01’);

参数说明:

-s svm类型:SVM设置类型(默认0)
  0 – C-SVC
  1 --v-SVC
  2 – 一类SVM
  3 – e -SVR
  4 – v-SVR

-t 核函数类型:核函数设置类型(默认2)
  0 – 线性:u’v
  1 – 多项式:(ru’v + coef0)^degree
  2 – RBF函数:exp(-r|u-v|^2)
  3 –sigmoid:tanh(r
u’v + coef0)

-g r(gama):核函数中的gamma函数设置(针对多项式/rbf/sigmoid核函数)

-c cost:设置C-SVC,e -SVR和v-SVR的参数(损失函数)(默认1),惩罚系数

-n nu:设置v-SVC,一类SVM和v- SVR的参数(默认0.5)

-p p:设置e -SVR 中损失函数p的值(默认0.1)

-d degree:核函数中的degree设置(针对多项式核函数)(默认3)

-wi weight:设置第几类的参数C为weight*C(C-SVC中的C)(默认1)

-v n: n-fold交互检验模式,n为fold的个数,必须大于等于2

libsvm使用误区----------------------

(1) 直接将训练集合和测试集合简单归一化到[0,1]区间,可能导致实验结果很差。

(2) 如果样本的特征数非常多,那么就不必使用RBF核将样本映射到高维空间。
a) 在特征数非常多的情况下,使用线性核,结果已经非常好,并且只需要选择参数C即可。
b) 虽然说RBF核的结果至少比线性核好,前提下搜索整个的空间。
(3) 样本数<<特征数的情况:推荐使用线性核,可以达到与RBF同样的性能。

(4) 样本数和特征数都非常多:推荐使用liblinear,更少的时间和内存,可比的准确率。

(5) 样本数>>特征数:如果想使用线性模型,可以使用liblinear,并且使用-s 2参数

English:
libsvm_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)
4 – precomputed kernel (kernel values in training_instance_matrix)
-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 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

-v n: n-fold cross validation mode

Chinese:
Options:可用的选项即表示的涵义如下
  -s svm类型:SVM设置类型(默认0)
  0 – C-SVC
  1 --v-SVC
  2 – 一类SVM
  3 – e -SVR
  4 – v-SVR
  -t 核函数类型:核函数设置类型(默认2)
  0 – 线性:u’v
  1 – 多项式:(ru’v + coef0)^degree
  2 – RBF函数:exp(-gamma|u-v|^2)
  3 –sigmoid:tanh(r
u’v + coef0)
  -d degree:核函数中的degree设置(针对多项式核函数)(默认3)
  -g r(gama):核函数中的gamma函数设置(针对多项式/rbf/sigmoid核函数)(默认

1/ k)
  -r coef0:核函数中的coef0设置(针对多项式/sigmoid核函数)((默认0)
  -c cost:设置C-SVC,e -SVR和v-SVR的参数(损失函数)(默认1)
  -n nu:设置v-SVC,一类SVM和v- SVR的参数(默认0.5)
  -p p:设置e -SVR 中损失函数p的值(默认0.1)
  -m cachesize:设置cache内存大小,以MB为单位(默认40)
  -e eps:设置允许的终止判据(默认0.001)
  -h shrinking:是否使用启发式,0或1(默认1)
  -wi weight:设置第几类的参数C为weight*C(C-SVC中的C)(默认1)
  -v n: n-fold交互检验模式,n为fold的个数,必须大于等于2
  其中-g选项中的k是指输入数据中的属性数。option -v 随机地将数据剖分为n部

分并计算交互检验准确度和均方根误差。以上这些参数设置可以按照SVM的类型和核函

数所支持的参数进行任意组合,如果设置的参数在函数或SVM类型中没有也不会产生影

响,程序不会接受该参数;如果应有的参数设置不正确,参数将采用默认值。

————————————————
版权声明:本文为CSDN博主「好多鱼哦」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/shuke1991/article/details/5348757

  • 30
    点赞
  • 166
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值