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
81537 11408528
The compact model consumes less memory than the full model.