piml.models.GAMRegressor

class piml.models.GAMRegressor(feature_names=None, feature_types=None, spline_order=3, n_splines=20, lam=0.6, max_iter=100)

A wrapper of generalized additive model regressor in pygam.

Parameters:
feature_nameslist or None, default=None

The list of feature names.

feature_typeslist or None, default=None

The list of feature types. Available types include “numerical” and “categorical”.

n_splines: int, default=3

Number of splines to use for the feature function. Must be non-negative.

spline_order: int, default=20

Order of spline to use for the feature function. Must be non-negative.

lam: float or iterable of floats, default=0.6

Strength of smoothing penalty. Must be a positive float. Larger values enforce stronger smoothing. If single value is passed, it will be repeated for every penalty. If iterable is passed, the length of lam must be equal to the length of penalties.

max_iter: int, default=100

Maximum number of iterations allowed for the solver to converge.

Attributes:
feature_names_list of str

The feature name list of all input features.

feature_types_list of str

The feature type list of all input features.

Methods

fit(X, y[, sample_weight])

Fit the gam model

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

parse_model()

Interpret the model using functional ANOVA.

partial_dependence(fidx, X)

Partial dependence of given effect index.

predict(X)

Returns numpy array of raw predicted value.

score(X, y[, sample_weight])

Returns R2 metric for the given data.

set_params(**params)

Set the parameters of this estimator.

fit(X, y, sample_weight=None)

Fit the gam model

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Data features.

ynp.ndarray of shape (n_samples, )

Target response.

sample_weightnp.ndarray of shape (n_samples, )

Sample weight.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

parse_model()

Interpret the model using functional ANOVA.

Returns:
An instance of FANOVAINterpreter

The interpretation results.

partial_dependence(fidx, X)

Partial dependence of given effect index.

Parameters:
fidxtuple of int

The main effect or pairwise interaction feature index.

Xnp.ndarray of shape (n_samples, n_features)

Data features.

Returns:
prednp.ndarray of shape (n_samples, )

numpy array of predicted class values.

predict(X)

Returns numpy array of raw predicted value.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Data features.

Returns:
prednp.ndarray of shape (n_samples, )

numpy array of predicted class values.

score(X, y, sample_weight=None)

Returns R2 metric for the given data.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Data features.

ynp.ndarray of shape (n_samples, )

Target response.

sample_weightnp.ndarray of shape (n_samples, )

Sample weight.

Returns:
scorefloat

R2 value.

set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

Examples using piml.models.GAMRegressor

GAM Regression (California Housing)

GAM Regression (California Housing)