www.gusucode.com > stats 源码程序 matlab案例代码 > stats/SaveCompactSVMModelForCodeGenerationExample.m

    %% Save SVM Model for Code Generation
% To generate C code that classifies new observations based on a
% trained SVM model, you must first save the trained model to disk. This
% example shows how to perform this first step.
%%
% Load the |ionosphere| data set.
load ionosphere
%%
% Train an SVM classification model using the entire data set.
% Specify to standardize the data.
Mdl = fitcsvm(X,Y,'Standardize',true);
%%
% |Mdl| is a |ClassificationSVM| model.
%%
% Save the SVM classification model to the file |'SVMIonosphere.mat'|.
saveCompactModel(Mdl,'SVMIonosphere');
%%
% |'SVMIonosphere.mat'| appears in your present working directory.
% |saveCompactModel| reduces the memory footprint of the model by removing
% properties that are not needed for prediction, for example, the training
% data. Then, |saveCompactModel| saves a structure array that characterizes
% |Mdl| in |'SVMIonosphere.mat'|.
%%
% In the function that you declare that classifies new data using the
% trained SVM model, load the structure array in |'SVMIonosphere.mat'|.