saveCompactModel
(Removed) Save model object in file for code generation
saveCompactModel has been removed. Use saveLearnerForCoder
instead. To update your code, simply replace instances of
saveCompactModel with
saveLearnerForCoder.
Description
To generate C/C++ code for the object functions
(predict, random,
knnsearch, or rangesearch)
of machine learning models, use saveCompactModel,
loadCompactModel, and codegen (MATLAB Coder). After training
a machine learning model, save the model by using
saveCompactModel. Define an entry-point
function that loads the model by using loadCompactModel
and calls an object function. Then use codegen or the
MATLAB®
Coder™ app to generate C/C++ code. Generating C/C++ code requires
MATLAB
Coder.
This flow chart shows the code generation workflow for the object functions of
machine learning models. Use saveCompactModel for the
highlighted step.
![]()
saveCompactModel(
prepares a classification model, regression model, or nearest
neighbor searcher (Mdl,filename)Mdl) for code generation and
saves it in the MATLAB formatted binary file (MAT-file) named
filename. You can pass
filename to loadCompactModel to reconstruct the model object
from the filename file.
Examples
Input Arguments
Algorithms
saveCompactModel
prepares a machine learning model (Mdl) for code
generation. The function removes some properties that are not required for prediction.
For a model that has a corresponding compact model, the
saveCompactModelfunction applies the appropriatecompactfunction to the model before saving it.For a model that does not have a corresponding compact model, such as
ClassificationKNN,ClassificationLinear,RegressionLinear,ExhaustiveSearcher, andKDTreeSearcher, thesaveCompactModelfunction removes properties such as hyperparameter optimization properties, training solver information, and others.
loadCompactModel loads the model saved
by saveCompactModel.
Alternative Functionality
Use a coder configurer created by
learnerCoderConfigurerfor the models listed in this table.Model Coder Configurer Object Binary decision tree for multiclass classification ClassificationTreeCoderConfigurerSVM for one-class and binary classification ClassificationSVMCoderConfigurerLinear model for binary classification ClassificationLinearCoderConfigurerMulticlass model for SVMs and linear models ClassificationECOCCoderConfigurerBinary decision tree for regression RegressionTreeCoderConfigurerSupport vector machine (SVM) regression RegressionSVMCoderConfigurerLinear regression RegressionLinearCoderConfigurerAfter training a machine learning model, create a coder configurer of the model. Use the object functions and properties of the configurer to configure code generation options and to generate code for the
predictandupdatefunctions of the model. If you generate code using a coder configurer, you can update model parameters in the generated code without having to regenerate the code. For details, see Code Generation for Prediction and Update Using Coder Configurer.
Version History
Introduced in R2016bSee Also
loadCompactModel | codegen (MATLAB Coder) | saveLearnerForCoder