(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:

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:

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;
        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;
        return sum;

sv_coef is the first column of model file, which is yiα. (coefficients for SVs in decision functions (sv_coef[k-1][l]) )
And the decision function is: sgn(i=1lyiαiK(xi,x)ρ), ρ=b.
Kernel::k_function(x,model->SV[i],model->param): “x” and “SV[i]” are vectors here;
For function k_function(const svm_node *x, const svm_node *y, const svm_parameter& param), only linear and poly are shown here:

    case LINEAR:
        return dot(x,y);
    case POLY:
        return powi(param.gamma*dot(x,y)+param.coef0,;
发布了18 篇原创文章 · 获赞 6 · 访问量 7万+


©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客