# CompactRegressionGAM

## Description

`CompactRegressionGAM`

is a compact version of a `RegressionGAM`

model
object (GAM for regression). The compact model does not include the data used for training the
model. Therefore, you cannot perform some tasks, such as cross-validation, using the compact
model. Use a compact model for tasks such as predicting the responses of new
data.

## Creation

Create a `CompactRegressionGAM`

object from a full `RegressionGAM`

model
object by using `compact`

.

## Properties

### GAM Properties

`Interactions`

— Interaction term indices

two-column matrix of positive integers | `[]`

This property is read-only.

Interaction term indices, specified as a `t`

-by-2 matrix of positive
integers, where `t`

is the number of interaction terms in the model.
Each row of the matrix represents one interaction term and contains the column indexes
of the predictor data `X`

for the interaction term. If the model does
not include an interaction term, then this property is empty
(`[]`

).

The software adds interaction terms to the model in the order of importance based on the
*p*-values. Use this property to check the order of the interaction
terms added to the model.

**Data Types: **`double`

`Intercept`

— Intercept term of model

numeric scalar

This property is read-only.

Intercept (constant) term of the model, which is the sum of the intercept terms in the predictor trees and interaction trees, specified as a numeric scalar.

**Data Types: **`single`

| `double`

`IsStandardDeviationFit`

— Flag indicating whether standard deviation model is fit

`false`

| `true`

Flag indicating whether a model for the standard deviation of the response
variable is fit, specified as `false`

or `true`

.
Specify the `'FitStandardDeviation'`

name-value argument of
`fitrgam`

as `true`

to fit the model for the
standard deviation.

If `IsStandardDeviationFit`

is `true`

, then
you can evaluate the standard deviation at a new observation by using `predict`

.
This function also returns the prediction intervals of the response variable,
evaluated at given observations.

**Data Types: **`logical`

### Other Regression Properties

`CategoricalPredictors`

— Categorical predictor indices

vector of positive integers | `[]`

This property is read-only.

Categorical predictor
indices, specified as a vector of positive integers. `CategoricalPredictors`

contains index values indicating that the corresponding predictors are categorical. The index
values are between 1 and `p`

, where `p`

is the number of
predictors used to train the model. If none of the predictors are categorical, then this
property is empty (`[]`

).

**Data Types: **`double`

`ExpandedPredictorNames`

— Expanded predictor names

cell array of character vectors

This property is read-only.

Expanded predictor names, specified as a cell array of character vectors.

`ExpandedPredictorNames`

is the same as `PredictorNames`

for a generalized additive model.

**Data Types: **`cell`

`PredictorNames`

— Predictor variable names

cell array of character vectors

This property is read-only.

Predictor variable names, specified as a cell array of character vectors. The order of the
elements in `PredictorNames`

corresponds to the order in which the
predictor names appear in the training data.

**Data Types: **`cell`

`ResponseName`

— Response variable name

character vector

This property is read-only.

Response variable name, specified as a character vector.

**Data Types: **`char`

`ResponseTransform`

— Response transformation function

`'none'`

| function handle

Response transformation function, specified as `'none'`

or a function handle.
`ResponseTransform`

describes how the software transforms raw
response values.

For a MATLAB^{®} function or a function that you define, enter its function handle. For
example, you can enter ```
Mdl.ResponseTransform =
@
```

, where
*function*

accepts a numeric vector of the
original responses and returns a numeric vector of the same size containing the
transformed responses.*function*

**Data Types: **`char`

| `function_handle`

## Object Functions

### Interpret Prediction

`lime` | Local interpretable model-agnostic explanations (LIME) |

`partialDependence` | Compute partial dependence |

`plotLocalEffects` | Plot local effects of terms in generalized additive model (GAM) |

`plotPartialDependence` | Create partial dependence plot (PDP) and individual conditional expectation (ICE) plots |

`shapley` | Shapley values |

## Examples

### Reduce Size of Generalized Additive Model

Reduce the size of a full generalized additive model (GAM) for regression by removing the training data. Full models hold the training data. You can use a compact model to improve memory efficiency.

Load the `carbig`

data set.

`load carbig`

Specify `Acceleration`

, `Displacement`

, `Horsepower`

, and `Weight`

as the predictor variables (`X`

) and `MPG`

as the response variable (`Y`

).

X = [Acceleration,Displacement,Horsepower,Weight]; Y = MPG;

Train a GAM using `X`

and `Y`

.

Mdl = fitrgam(X,Y)

Mdl = RegressionGAM ResponseName: 'Y' CategoricalPredictors: [] ResponseTransform: 'none' Intercept: 26.9442 IsStandardDeviationFit: 0 NumObservations: 398

`Mdl`

is a `RegressionGAM`

model object.

Reduce the size of the model.

CMdl = compact(Mdl)

CMdl = CompactRegressionGAM ResponseName: 'Y' CategoricalPredictors: [] ResponseTransform: 'none' Intercept: 26.9442 IsStandardDeviationFit: 0

`CMdl`

is a `CompactRegressionGAM`

model object.

Display the amount of memory used by each regression model.

whos('Mdl','CMdl')

Name Size Bytes Class Attributes CMdl 1x1 578332 classreg.learning.regr.CompactRegressionGAM Mdl 1x1 612126 RegressionGAM

The full model (`Mdl`

) is larger than the compact model (`CMdl`

).

To efficiently predict responses for new observations, you can remove `Mdl`

from the MATLAB® Workspace, and then pass `CMdl`

and new predictor values to `predict`

.

## Version History

**Introduced in R2021a**

## 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)