Train a univariate GAM for regression, which contains linear terms for predictors. Then, interpret the prediction for a specified data instance by using the `plotLocalEffects`

function.

Load the data set `NYCHousing2015`

.

The data set includes 10 variables with information on the sales of properties in New York City in 2015. This example uses these variables to analyze the sale prices (`SALEPRICE`

).

Preprocess the data set. Remove outliers, convert the `datetime`

array (`SALEDATE`

) to the month numbers, and move the response variable (`SALEPRICE`

) to the last column.

Display the first three rows of the table.

ans=*3×10 table*
BOROUGH NEIGHBORHOOD BUILDINGCLASSCATEGORY RESIDENTIALUNITS COMMERCIALUNITS LANDSQUAREFEET GROSSSQUAREFEET YEARBUILT SALEDATE SALEPRICE
_______ ____________ ____________________________ ________________ _______________ ______________ _______________ _________ ________ _________
2 {'BATHGATE'} {'01 ONE FAMILY DWELLINGS'} 1 0 4750 2619 1899 8 0
2 {'BATHGATE'} {'01 ONE FAMILY DWELLINGS'} 1 0 4750 2619 1899 8 0
2 {'BATHGATE'} {'01 ONE FAMILY DWELLINGS'} 1 1 1287 2528 1899 12 0

Train a univariate GAM for the sale prices. Specify the variables for `BOROUGH`

, `NEIGHBORHOOD`

, `BUILDINGCLASSCATEGORY`

, and `SALEDATE`

as categorical predictors.

`Mdl`

is a `RegressionGAM`

model object.

Display the estimated intercept (constant) term of `Mdl`

.

The intercept term value is close to the average of the response variable in a regression GAM if the training data does not include `NaN`

values. Compute average of the response variable.

Predict the sale price for the first observation of the training data, and plot the local effects of the terms in `Mdl`

on the prediction. Specify `'IncludeIntercept',true`

to include the intercept term in the plot.

The `predict`

function predicts the sale price for the first observation as `4.4421e5`

. The `plotLocalEffects`

function creates a horizontal bar graph that shows the local effects of the terms in `Mdl`

on the prediction. Each local effect value shows the contribution of each term to the predicted sale price.