0

在matlab中,我有一个程序,这个实现线性支持向量机来做机器学习。

库在训练阶段输出一个表示模型的结构。此结构将用于测试阶段。

我想将这个结构保存到一个文件中,这样我就不必每次都经历训练阶段。

我已经尝试过psychtoolboxWriteStructsToText()and ReadStructsFromText(),但是由于在将结构读入内存时缓冲区溢出,它们失败了。

输出的结构是非常大量的数据(几十兆字节),所以这可能是问题所在。

结构:

    -Parameters: Parameters
    -nr_class: number of classes; = 2 for regression
    -nr_feature: number of features in training data (without including the bias term)
    -bias: If >= 0, we assume one additional feature is added to the end
        of each data instance.
    -Label: label of each class; empty for regression
    -w: a nr_w-by-n matrix for the weights, where n is nr_feature
        or nr_feature+1 depending on the existence of the bias term.
        nr_w is 1 if nr_class=2 and -s is not 4 (i.e., not
        multi-class svm by Crammer and Singer). It is
        nr_class otherwise.

编辑:

有谁知道如何解决这个错误?

>> save('mode.txt','-struct','model');
>> model = load('mode.txt');
??? Error using ==> load
Number of columns on line 1 of ASCII file C:\Users\jason\Dropbox\Homework\cs280\FINAL PROJECTO\mode.txt
must be the same as previous lines.
4

1 回答 1

2

最简单的方法是将结构保存到 .mat 文件:

outputStructure = yourTrainingFunction;

save('someFileName.mat','-struct','outputStructure');

并加载

outputStructure = load('someFileName.mat')

请注意,如果您的文件非常大,您可能必须在 Matlab 的常规设置中设置适当的兼容性(如果我没记错的话,7.3 之前的保存文件版本无法处理 >2GB 的文件)。

于 2012-12-05T02:41:46.263 回答