libsvm中各参数介绍(包括里面结构体参数的介绍)

在我的项目中用到了libsvm中的函数,但是发现现在很多博客都是一样的,而且,很多参数都没有解释清楚。所以本文就介绍一下,如有错误请指正。


部分参考来源:
https://blog.csdn.net/tang_jin2015/article/details/22292535
https://www.cnblogs.com/codingmengmeng/p/6254325.html

先说一下libsvm中的数据格式:
label 1:value1 2:value2 3:value3
label: 如果是分类则为类标签,如果是回归则为真实值
1,2,3:是样本的序号,可以省略,例如第2个样本没有值,那就是1:value1 3:value3
value1,value2,value3:表示样本值

svm-train中函数参数详解:
-s svm类型:SVM设置类型(默认0)
0 -- C-SVC:C-支持向量分类机;参数C为惩罚系数,C越大表示对错误分类的惩罚越大,适当的参数C对分类Accuracy很关键,用于惩罚系数的。
1 -- v-SVC:v-支持向量分类机;由于C的选取比较困难,用另一个参数v代替C。C是“无意义”的,v是有意义的。(与C_SVC其实采用的模型相同,但是它们的参数C的范围不同,C_SVC采用的是0到正无穷,该类型是[0,1]。)v用于惩罚支持向量的个数。
2 – one class SVM:单类别-支持向量机,不需要类标号,用于支持向量的密度估计和聚类。也就是训练数据只有一个类标签,可以用于检测异常点。
3 -- e-SVR:ε-支持向量回归机,不敏感损失函数,对样本点来说,存在着一个不为目标函数提供任何损失值的区域。
4 -- v-SVR:n-支持向量回归机,由于EPSILON_SVR需要事先确定参数,然而在某些情况下选择合适的参数却不是一件容易的事情。而NU_SVR能够自动计算参数。

// 如果想自己调用函数来训练和预测,则可以参考如下的函数参数说明
struct svm_model *svm_train(const struct svm_problem *prob, const struct svm_parameter *param)
{
   struct svm_node
{
 
       int index;                 // 单个样本的序号
       double value;           // 单个样本对应的值
    
};
   struct svm_problem
{
 
       int l;                                  // 训练数据样本个数
       double *y;                      // 训练样本的label,如果是分类,则是标签值,如果是回归,则是真实值
       struct svm_node **x;    // 数组指针,指向每一个训练样本
 };
    /*
         例如:1  1:0.3 2:0.5 3:8.8
                   -1 1:0.6 3:1.8
         则:
                     l = 2
                     y[0] = 1 y[1] = -1
                    *x   = (1,0.3)(2,0.5)(3,8.8)
                     *x+1 = (1,0.6)(3,1.8)
    */
struct svm_parameter
{
 
   int svm_type;             // 应用类型:可以是C_SVC、NU_SVC、ONE_CLASS、EPSILON_SVR或NU_SVR其中的一种。
   int kernel_type;         // 核函数类型:可以是LINEAR、POLY、RBF、SIGMOID其中一种
   // 各核函数的定义如下所示:
   /*
   LINEAR: u’*v
   POLY: (gamma*u’*v + coef0)^degree
   RBF: exp(-gamma*|u-v|^2)
   SIGMOID: tanh(gamma*u’*v + coef0)
   PRECOMPUTED:训练 集文件中的核心值
   */ 
   
   int degree; /* for poly */
 
   double gamma; /* for poly/rbf/sigmoid */
 
   double coef0; /* for poly/sigmoid */
 
   /* these are for training only */
 
   double cache_size; /* in MB */
 
   double eps; /* stopping criteria */          // 一般取值有0.001,0.00001等
   double C; /* for C_SVC, EPSILON_SVR and NU_SVR */
 
   int nr_weight;  /* for C_SVC */
 
   int *weight_label; /* for C_SVC */
 
   double* weight;  /* for C_SVC */
 
   double nu; /* for NU_SVC, ONE_CLASS, and NU_SVR */
 
   double p; /* for EPSILON_SVR */
 
   int shrinking; /* use the shrinking heuristics */
 
   int probability; /* do probability estimates */
   
};
}
// 预测函数
double svm_predict_probability(const struct svm_model *model, const struct svm_node *x, double* prob_estimates)
{
     struct svm_model
       {
 
               struct svm_parameter param; /* parameter */
 
               int nr_class;  /* number of classes, = 2 in regression/one class svm */
 
               int l;   /* total #SV */
 
               struct svm_node **SV; /* SVs (SV[l]) */
 
               double **sv_coef; /* coefficients for SVs in decision functions (sv_coef[k-1][l]) */
 
               double *rho;  /* constants in decision functions (rho[k*(k-1)/2]) */
 
               double *probA;  /* pariwise probability information */
 
               double *probB;
 
             int *sv_indices;        /* sv_indices[0,...,nSV-1] are values in [1,...,num_traning_data] to indicate SVs in the training set */
 
           /* for classification only */
 
           int *label;  /* label of each class (label[k]) */
 
           int *nSV;  /* number of SVs for each class (nSV[k]) */
    
          /* nSV[0] + nSV[1] + ... + nSV[k-1] = l */
 
           /* XXX */
 
           int free_sv;  /* 1 if svm_model is created by svm_load_model*/
    
                              /* 0 if svm_model is created by svm_train */
   
    }; 
}






  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值