compact
Compact linear regression model
Description
returns the compact linear regression model compactMdl
= compact(mdl
)compactMdl
, which
is the compact version of the full, fitted linear regression model
mdl
.
Examples
Compact Linear Regression Model
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.
Load the largedata4reg
data set, which contains 15,000 observations and 45 predictor variables.
load largedata4reg
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 compactMdl
.
vars = whos('compactMdl','mdl'); [vars(1).bytes,vars(2).bytes]
ans = 1×2
81538 11409065
The compact model consumes less memory than the full model.
Input Arguments
mdl
— Linear regression model
LinearModel
object
Linear regression model, specified as a LinearModel
object created using fitlm
or stepwiselm
.
Output Arguments
compactMdl
— Compact linear regression model
CompactLinearModel
object
Compact linear regression model, returned as a CompactLinearModel
object.
A CompactLinearModel
object consumes less memory than a
LinearModel
object because a compact model does not
store the input data used to fit the model or information related to the
fitting process. 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.
Extended Capabilities
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced in R2016a
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)