SuperGLMRegressor#

class superglm.SuperGLMRegressor(
family: str | Distribution = 'poisson',
penalty: str | Penalty | None = None,
selection_penalty: float | Literal['auto'] | None = None,
spline_penalty: float | dict[str, float] | None = None,
features: dict | None = None,
spline_features: list[str | int] | None = None,
categorical_features: list[str | int] | None = None,
numeric_features: list[str | int] | None = None,
feature_names: list[str] | None = None,
n_knots: int | list[int] = 10,
degree: int = 3,
categorical_base: str = 'most_exposed',
offset: str | int | list[str | int] | None = None,
weight_semantics: Literal['prior', 'frequency'] = 'prior',
*,
terms: list[TermInput] | None = None,
smoothing: Literal['fixed', 'reml'] = 'fixed',
)#

Bases: BaseEstimator, RegressorMixin

Penalised GLM for count / continuous regression.

Accepts DataFrame or ndarray input. See module docstring for details on ndarray mode and penalty defaults.

Parameters:
familystr or Distribution

Distribution family. Strings: "poisson", "gamma", "gaussian". For parameterized families use objects: families.tweedie(p=1.5), families.nb2(theta=1.0). For binary classification use SuperGLMClassifier.

penaltystr, Penalty, or None

Penalty type. None (default) means no feature-selection penalty when selection_penalty is also None or zero. Explicit automatic or positive selection strength auto-upgrades to "group_lasso".

selection_penaltyfloat, {“auto”}, or None

Group penalty strength. None and zero disable feature selection; "auto" explicitly calibrates the strength from the fit data.

spline_penaltyfloat, dict[str, float] or None

How strongly each spline is smoothed. Defaults to 0.1. A float sets every term; a dict sets terms by name ("x", "x:<penalty>", "x:c[a]") and leaves the terms it does not name unsmoothed. See SuperGLM for the keys.

featuresdict[str, FeatureSpec] or None

Native-style feature specs. Mutually exclusive with the shorthand wrapper arguments (spline_features, categorical_features, numeric_features, non-default n_knots/degree/categorical_base).

spline_featureslist of str or int, or None

Columns to treat as spline features (by name or index).

categorical_featureslist of str or int, or None

Columns to treat as categorical (by name or index). Required for ndarray input if any columns are categorical.

numeric_featureslist of str or int, or None

Columns to treat as numeric (by name or index). Unspecified columns default to numeric.

feature_nameslist of str or None

Column names for ndarray input. Ignored for native DataFrames.

n_knotsint or list of int

Interior knots for spline features.

degreeint

B-spline degree (default 3).

categorical_basestr

Base level strategy ("most_exposed" or "first").

offsetstr, int, list, or None

Offset column(s) by name or index.

weight_semantics{“prior”, “frequency”}

What sample_weight says about a row. "prior" (default) reads it as a precision, Var(Y_i) = phi V(mu_i) / w_i; "frequency" reads it as a replication count, where an integer weight is exactly a repeated row. Passed through to SuperGLM.

termslist of term declarations or None

Keyword only. The model’s terms as one list, passed through to SuperGLM as terms=. Mutually exclusive with features and with the shorthand wrapper arguments, as features is. The model reads the declared columns.

smoothing{“fixed”, “reml”}, default=”fixed”

Keyword only. "fixed" fits with SuperGLM.fit at the spline_penalty smoothing; "reml" fits with SuperGLM.fit_reml, which selects every smoothing parameter by REML and is the fit random effects and factor smooths need.

score(X, y, sample_weight=None) → float#

R² of predict on X, as scikit-learn’s RegressorMixin.score.

A row of positive weight with no predicted mean is refused with NoPredictedMeanError, naming it; one of weight zero is left out.

summary(
alpha: float = 0.05,
detail: str = 'compact',
level_display: str = 'expanded',
)#

Return the fitted model summary with categorical display control.

set_fit_request(
*,
sample_weight: bool | None | str = '$UNCHANGED$',
) → SuperGLMRegressor#

Configure whether metadata should be requested to be passed to the fit method.

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 (see sklearn.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 to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

set_score_request(
*,
sample_weight: bool | None | str = '$UNCHANGED$',
) → SuperGLMRegressor#

Configure whether metadata should be requested to be passed to the score method.

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 (see sklearn.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 to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • 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.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.