Libsvm save model file in binary format

妖精的绣舞 提交于 2019-12-12 00:28:23

问题


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?


回答1:


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');

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);

More details are included in the github.



来源:https://stackoverflow.com/questions/20624343/libsvm-save-model-file-in-binary-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!