libsvm savemodel and loadmodel

本文介绍了libsvm库中模型的保存与加载操作,提供了C语言实现的savemodel和loadmodel函数,并给出了使用示例。

savemodel 和 loadmodel的c代码如下:

#include "svm.h"
#include "mex.h"
#include "svm_model_matlab.h"

static void fake_answer(mxArray *plhs[])
{
    plhs[0] = mxCreateDoubleMatrix(0, 0, mxREAL);
}

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    struct svm_model *model;
    char *filename;
    const char *error_msg;
    int nr_feat;

    // check input
    if(nrhs != 2) {
        mexPrintf("Usage: model = libsvmloadmodel('filename', num_of_feature);\n");
        fake_answer(plhs);
        return;
    }
    if(!mxIsChar(prhs[0]) || mxGetM(prhs[0])!=1) {
        mexPrintf("filename should be given as string\n");
        fake_answer(plhs);
        return;
    }
    if(mxGetNumberOfElements(prhs[1])!=1) {
        mexPrintf("number of features should be given as scalar\n");
        fake_answer(plhs);
        return;
    }

    // get filename and number of features
    filename = mxArrayToString(prhs[0]);
    nr_fea
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值