Main Content

compact

Compact generalized linear regression model

Description

compactMdl = compact(mdl) returns the compact generalized linear regression model compactMdl, which is the compact version of the full, fitted generalized linear regression model mdl.

example

Examples

collapse all

Fit a generalized linear regression model to data and reduce the size of a full, fitted 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 generalized linear regression model to the data using the first 15 predictor variables.

mdl = fitglm(X(:,1:15),Y);

Compact the model.

compactMdl = compact(mdl);

The compact model discards the original sample data and some information related to the fitting process, so it uses less memory than the full model.

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

       17060     4384077

The compact model consumes less memory than the full model.

Input Arguments

collapse all

Generalized linear regression model, specified as a GeneralizedLinearModel object created using fitglm or stepwiseglm.

Output Arguments

collapse all

Compact generalized linear regression model, returned as a CompactGeneralizedLinearModel object.

A CompactGeneralizedLinearModel object consumes less memory than a GeneralizedLinearModel 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 GeneralizedLinearModel object functions that require the input data do not work with a compact model.

Extended Capabilities

Version History

Introduced in R2016b