loadCompactModel
(Removed) Reconstruct model object from saved model for code generation
loadCompactModel
has been removed. Use loadLearnerForCoder
instead. To update your code, simply replace
instances of loadCompactModel
with
loadLearnerForCoder
.
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 loadCompactModel
for the highlighted step.
reconstructs a classification model, regression model, or nearest neighbor searcher
(Mdl
= loadCompactModel(filename
)Mdl
) from the model stored in the MATLAB formatted binary file (MAT-file) named filename
.
You must create the filename
file by using saveCompactModel
.
Examples
Input Arguments
Output 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
saveCompactModel
function applies the appropriatecompact
function to the model before saving it.For a model that does not have a corresponding compact model, such as
ClassificationKNN
,ClassificationLinear
,RegressionLinear
,ExhaustiveSearcher
, andKDTreeSearcher
, thesaveCompactModel
function 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
learnerCoderConfigurer
for the models listed in this table.Model Coder Configurer Object Binary decision tree for multiclass classification ClassificationTreeCoderConfigurer
SVM for one-class and binary classification ClassificationSVMCoderConfigurer
Linear model for binary classification ClassificationLinearCoderConfigurer
Multiclass model for SVMs and linear models ClassificationECOCCoderConfigurer
Binary decision tree for regression RegressionTreeCoderConfigurer
Support vector machine (SVM) regression RegressionSVMCoderConfigurer
Linear regression RegressionLinearCoderConfigurer
After 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
predict
andupdate
functions 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.
Extended Capabilities
Version History
Introduced in R2016bSee Also
saveCompactModel
| codegen
(MATLAB Coder) | loadLearnerForCoder