GAM#

class sknormod.gam.GAM(mu_formula='y ~ 1')#

Generalized Additive Model (GAM) implemented using the mgcv package in R. Formula doesn’t work well yet.

Parameters:
mu_formulastr, default=”y ~ 1”

The formula specifying the model for the mean response. It should be a valid formula according to R’s formula syntax.

Examples

>>> from sknormod.gam import GAM
>>> import numpy as np
>>> X = np.arange(100).reshape(100, 1)
>>> y = np.random.normal(0, 1, 100)
>>> gam = GAM(mu_formula="y ~ 1")
>>> gam.fit(X, y)
GAM()
Attributes:
fitted_model_R object

The fitted GAM model obtained from R’s mgcv package.

resid_sd_float

The standard deviation of the residuals of the fitted model.

Methods

fit(X, y)

Fit the GAM model.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

predict_distr_p(X, p)

Predict the percentiles of the distribution.

predict_distr_params(X)

Predict distribution parameters for given input samples.

score(X, y)

Compute the logarithmic score of the predicted distribution parameters against the true values.

set_params(**params)

Set the parameters of this estimator.

transform_to_p(X, y)

Transform the target values to percentiles.

transform_to_z(X, y)

Transform the target values to z-scores.

fit(X, y)#

Fit the GAM model.

Parameters:
Xarray-like or sparse matrix of shape (n_samples, n_features)

The input samples.

yarray-like of shape (n_samples,)

The target values.

Returns:
selfobject

Fitted estimator.

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.

predict_distr_p(X, p)#

Predict the percentiles of the distribution.

Parameters:
Xarray-like or sparse matrix of shape (n_samples, n_features)

The input samples.

parray-like of shape (n_percentiles,)

The percentiles to predict.

Returns:
percentileslist of floats

The predicted percentiles.

predict_distr_params(X)#

Predict distribution parameters for given input samples.

Parameters:
Xarray-like or sparse matrix of shape (n_samples, n_features)

The input samples.

Returns:
paramsarray-like of shape (n_samples, 2)

Predicted distribution parameters where each row represents [mu, sigma].

score(X, y)#

Compute the logarithmic score of the predicted distribution parameters against the true values.

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.

transform_to_p(X, y)#

Transform the target values to percentiles.

transform_to_z(X, y)#

Transform the target values to z-scores.

Examples using sknormod.gam.GAM#

From LM to GAMLSS

From LM to GAMLSS