Implementation:Scikit learn Scikit learn GeneralizedLinearRegressor
| Knowledge Sources | |
|---|---|
| Domains | Machine Learning, Generalized Linear Models |
| Last Updated | 2026-02-08 15:00 GMT |
Overview
Concrete tool for regression via penalized Generalized Linear Models with exponential dispersion family distributions provided by scikit-learn.
Description
_GeneralizedLinearRegressor is the base class for GLM regressors in scikit-learn, fitting the mean of the target y as y_pred = h(X * w) with an inverse link function h. It minimizes an objective combining the unit deviance with L2 regularization. The module provides three public estimators: PoissonRegressor (log link, Poisson distribution), GammaRegressor (log link, Gamma distribution), and TweedieRegressor (configurable power parameter). These support both L-BFGS and Newton-Cholesky solvers.
Usage
Use PoissonRegressor for count data modeling (e.g., event frequencies), GammaRegressor for positive continuous targets with constant coefficient of variation (e.g., insurance claims), and TweedieRegressor when you need to model distributions in the Tweedie family with a specific power parameter. These are preferred over ordinary least squares when the target distribution is non-Gaussian.
Code Reference
Source Location
- Repository: scikit-learn
- File: sklearn/linear_model/_glm/glm.py
Signature
class _GeneralizedLinearRegressor(RegressorMixin, BaseEstimator):
"""Regression via a penalized Generalized Linear Model (GLM)."""
class PoissonRegressor(_GeneralizedLinearRegressor):
"""Generalized Linear Model with a Poisson distribution."""
class GammaRegressor(_GeneralizedLinearRegressor):
"""Generalized Linear Model with a Gamma distribution."""
class TweedieRegressor(_GeneralizedLinearRegressor):
"""Generalized Linear Model with a Tweedie distribution."""
Import
from sklearn.linear_model import PoissonRegressor, GammaRegressor, TweedieRegressor
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| alpha | float | No | Regularization strength multiplying the L2 penalty (default=1.0) |
| fit_intercept | bool | No | Whether to add a bias/intercept to the linear predictor (default=True) |
| solver | str | No | Optimization algorithm: 'lbfgs' or 'newton-cholesky' (default='lbfgs') |
| max_iter | int | No | Maximum number of iterations for the solver (default=100) |
| tol | float | No | Stopping criterion tolerance (default=1e-4) |
| warm_start | bool | No | Reuse previous solution as initialization (default=False) |
| verbose | int | No | Verbosity level for the solver (default=0) |
| power | float | No | Tweedie power parameter (TweedieRegressor only, default=0.0) |
| link | str | No | Link function: 'auto', 'identity', or 'log' (TweedieRegressor only) |
Outputs
| Name | Type | Description |
|---|---|---|
| coef_ | ndarray of shape (n_features,) | Estimated coefficients for the features |
| intercept_ | float | Intercept (bias) term in the model |
| n_iter_ | int | Actual number of iterations used in the solver |
Usage Examples
Basic Usage
from sklearn.linear_model import PoissonRegressor
import numpy as np
X = np.array([[1, 2], [2, 3], [3, 4], [4, 5]])
y = np.array([1, 3, 7, 12])
model = PoissonRegressor(alpha=0.5)
model.fit(X, y)
print("Coefficients:", model.coef_)
print("Predictions:", model.predict(X))