libsvm源代码注释+算法描述:svm_predict

(I will try my best to make this note clearer. We mainly discuss one_class case while others will be introduced in the future.)

Starting from the usage of svm-predict:
./svm-predict svmguide1.t svmguide1.model svmguide1.t.predict
(Example data can be downloaded here: https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/)

This is copied from the instruction of libsvm.

The model is loaded from svmguide1.model, which is output by training before.
i.e. model=svm_load_model(svmguide1.model)

Later, the prediction will be written in the file: svmguide1.t.predict.

the MAIN functions are:

predict(input,output);
svm_predict(model, x);  //x data is used for prediction
svm_predict_values(model, x, dec_values); 
//dec_values is one for one_class, or nr_class*(nr_class-1)/2

For function: svm_predict_values(const svm_model model, const svm_node *x, double dec_values):

    double *sv_coef = model->sv_coef[0];
    double sum = 0;
    for(i=0;i<model->l;i++)
        sum += sv_coef[i] * Kernel::k_function(x,model->SV[i],model->param);
    sum -= model->rho[0];
    *dec_values = sum;
    if(model->param.svm_type == ONE_CLASS)
        return (sum>0)?1:-1;
    else
        return sum;
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值