问题描述
我正在为libsvm训练一个巨大的数据文件,结果训练文件太大.有什么方法可以将libsvm库模型文件保存为二进制格式?
I am training a huge data file for libsvm and the resulting training file is too large. Is there any way to save the libsvm libraries model file in binary format?
推荐答案
如果您使用的是Matlab:下载 svm_savemodel.c 和 svm_model_matlab.c (libsvm中已包含此文件,您可以尝试使用原始版本,如果它不起作用,请尝试此链接)到您的libsvm目录.编译Mex文件(mex svm_savemodel.c
),它应该可以工作:
If you are using Matlab:Download svm_savemodel.c and svm_model_matlab.c (this is already included in libsvm, you can try to use the original one, but if it doesn't work, try this link) to your libsvm dir. Compile the Mex file (mex svm_savemodel.c
), then it should work:
%save model model
fid = fopen('model.bin','w');
model = fwrite(fid, model, 'int16');
%load('model.mat');
fid = fopen('model.bin','rb');
model = fread(fid, model, 'int16');
svm_savemodel(model,'model.model');
如果您使用的是C ++:有一个将模型保存到文件的功能:
If you are using C++:There is a function that saves a model to a file:
int svm_save_model(const char *model_file_name, const struct svm_model *model);
更多详细信息包含在 github 中.
More details are included in the github.
这篇关于Libsvm以二进制格式保存模型文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!