如何把在matlab上用libsvm训练出来的模型保存为.model

本文介绍了在MATLAB R2016a上利用libsvm 3.23训练SVM模型后,如何保存模型为.model文件。主要步骤包括修改svm_savemodel.c代码,更新make.m文件,添加编译器,设置环境变量,编译并生成svm_savemodel.mexw64,最后调用函数保存模型。
摘要由CSDN通过智能技术生成

用matlab中libsvm进行svm训练后,需要将模型文件保存下来,网上找了好久终于找到一个能用的了。
主要参考:https://www.tuicool.com/articles/QvAr22
本人版本:MATLAB R2016a,libsvm3.23
该版本输出的模型结构体域有11个,因此不需要像原博客修改代码。可直接使用svm_savemodel.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 status;

    // check input
    if(nrhs != 2) {
        mexPrintf("Usage: svm_savemodel(model, 'filename');\n");
        fake_answer(plhs);
        return;
    }
    if(!mxIsStruct(prhs[0])) {
        mexPrintf("model file should be a struct array\n");
        fake_answe
  • 1
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值