Compact linear regression model
CompactLinearModel is a compact version of a full linear
regression model object
LinearModel. Because a compact model does
not store the input data used to fit the model or information related to the fitting
CompactLinearModel object consumes less memory than a
LinearModel object. You can still use a compact model to predict
responses using new input data, but some
LinearModel object functions
do not work with a compact model.
|Plot main effects of predictors in linear regression model|
|Plot interaction effects of two predictors in linear regression model|
|Create partial dependence plot (PDP) and individual conditional expectation (ICE) plots|
|Plot of slices through fitted linear regression surface|
Fit a linear regression model to data and reduce the size of a full, fitted linear regression model by discarding the sample data and some information related to the fitting process.
largedata4reg data set, which contains 15,000 observations and 45 predictor variables.
Fit a linear regression model to the data.
mdl = fitlm(X,Y);
Compact the model.
compactMdl = compact(mdl);
The compact model discards the original sample data and some information related to the fitting process.
Compare the size of the full model
mdl and the compact model
vars = whos('compactMdl','mdl'); [vars(1).bytes,vars(2).bytes]
ans = 1×2 83506 11410618
The compact model consumes less memory than the full model.
Usage notes and limitations:
When you fit a model by using
stepwiselm, you cannot supply training
data in a table that contains a logical vector, character array, categorical array,
string array, or cell array of character vectors. Also, you cannot use the
'CategoricalVars' name-value pair argument. Code generation does not
support categorical predictors. To include
categorical predictors in a model, preprocess the categorical predictors by
dummyvar before fitting the
For more information, see Introduction to Code Generation.