generalized_additive_models.ExpectileGAM#
- class generalized_additive_models.ExpectileGAM(terms=None, *, expectile=0.5, fit_intercept=True, solver='pirls', max_iter=100, tol=0.0001, verbose=-1)#
Initialize an ExpectileGAM.
A GAM with a Normal distribution and an Identity link minimizes a weighted least squares objective
\[\ell(\beta) = \sum_i w_i (f(x_i; \beta) - y_i)^2 + \operatorname{penalty}(\beta)\]The ExpectileGAM minimizes a least asymmetrically weighted squares objective. The weights \(w_i\) are chosen based on the residuals \(\epsilon_i = f(x_i; \beta) - y_i\) and a desired expectile \(\tau\). The weights are given by
\[\begin{split}\epsilon_i = \begin{cases} \tau &\text{ if } \epsilon_i \leq 0 \\ 1 - \tau &\text{ if } \epsilon_i > 0 \end{cases}\end{split}\]For more information, see:
- Parameters:
terms (Term, TermList or list, optional) – The term(s) of the model. The argument can be a single term or a collection of terms. The features that the terms refer to must be present in the data set at fit and predict time. The default is None.
expectile (float, optional) – The expectile to fit to. The default is 0.5.
fit_intercept (TYPE, optional) – Whether or not to automatically add an intercept term to the terms. If an intercept is already present, then this setting has no effect. The default is True.
solver (str, optional) – The solver to use, currently only “pirls” is available, which stands for Penalized Iterated Reweighted Least Squares. The default is “pirls”.
max_iter (int, optional) – Maximum number of iterations in the solver. The default is 100.
tol (TYPE, optional) – Tolerance in the solver. The default is 0.0001.
verbose (int, optional) – Verbosity level. The higher the number, the more info is printed. The default is 0.
- Return type:
None.
- __init__(terms=None, *, expectile=0.5, fit_intercept=True, solver='pirls', max_iter=100, tol=0.0001, verbose=-1)#
Methods
__init__([terms, expectile, fit_intercept, ...])fit(X, y[, sample_weight])Fit model to data.
fit_quantile(X, y, quantile[, max_iter, ...])Find the expectile such that the empirical quantile matches quantile.
get_metadata_routing()Get metadata routing of this object.
get_params([deep])Get parameters for this estimator.
predict(X)Predict the expected value \(\mu\) with the model.
residuals(X, y, *[, residuals, standardized])Compute a vector of residuals.
sample(mu[, size, random_state])Sample from the posterior predictive distribution.
score(X, y[, sample_weight])Proportion deviance explained (pseudo \(r^2\)).
set_fit_request(*[, sample_weight])Configure whether metadata should be requested to be passed to the
fitmethod.set_params(**params)Set the parameters of this estimator.
set_score_request(*[, sample_weight])Configure whether metadata should be requested to be passed to the
scoremethod.summary([file])Print a model summary.
Attributes
DISTRIBUTIONSLINKS- fit_quantile(X, y, quantile, max_iter=20, tol=0.01, sample_weight=None)#
Find the expectile such that the empirical quantile matches quantile.
Finding the desired expectile is done by performing binary search.
- Parameters:
X (array-like, shape (n_samples, m_features)) – Training vectors, where n_samples is the number of samples and m_features is the number of features.
y (array-like, shape (n_samples,)) – Target values (integers in classification, real numbers in regression) For classification, labels must correspond to classes.
quantile (float on (0, 1)) – desired quantile to fit.
max_iter (int, default: 20) – maximum number of binary search iterations to perform
tol (float > 0, default: 0.01) – maximum distance between desired quantile and fitted quantile
weights (array-like shape (n_samples,) or None, default: None) – containing sample weights if None, defaults to array of ones
- Returns:
self
- Return type:
Fitted GAM object with updated expectile parameter.
Examples
>>> import numpy as np >>> from generalized_additive_models import ExpectileGAM, Intercept >>> rng = np.random.default_rng(42) >>> X = np.ones((1000, 1)) >>> y = rng.triangular(left=0, mode=0.5, right=1, size=(1000, 1)) >>> gam = ExpectileGAM(Intercept()).fit_quantile(X, y, quantile=0.9) >>> float((gam.predict(X) > y).mean()) 0.90... >>> gam.expectile 0.976...
- set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') ExpectileGAM#
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') ExpectileGAM#
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.