Predict responses for new observations using a generalized additive model that contains both linear and interaction terms for predictors. Use a memory-efficient model object, and specify whether to include interaction terms when predicting responses.

Load the `carbig`

data set, which contains measurements of cars made in the 1970s and early 1980s.

Specify `Acceleration`

, `Displacement`

, `Horsepower`

, and `Weight`

as the predictor variables (`X`

) and `MPG`

as the response variable (`Y`

).

Partition the data set into two sets: one containing training data, and the other containing new, unobserved test data. Reserve 10 observations for the new test data set.

Train a GAM that contains all the available linear and interaction terms in `X`

.

`Mdl`

is a `RegressionGAM`

model object.

Conserve memory by reducing the size of the trained model.

Name Size Bytes Class Attributes
CMdl 1x1 1228122 classreg.learning.regr.CompactRegressionGAM
Mdl 1x1 1262143 RegressionGAM

`CMdl`

is a `CompactRegressionGAM`

model object.

Predict the responses using both linear and interaction terms, and then using only linear terms. To exclude interaction terms, specify `'IncludeInteractions',false`

.

Create a table containing the observed response values and the predicted response values.

t=*10×3 table*
Observed Response Predicted Response Predicted Response Without Interactions
_________________ __________________ _______________________________________
27.9 23.04 23.649
NaN 37.163 35.779
NaN 25.876 21.978
13 12.786 14.141
36 28.889 27.281
19.9 22.199 18.451
24.2 23.995 24.885
12 14.247 13.982
38 33.797 33.528
13 12.225 11.127