Skip to content

ENH Add Poisson, Gamma, and Tweedie losses to SGDRegressor for incremental GLM learning - #33813

Open
berasaikat wants to merge 8 commits into
scikit-learn:mainfrom
berasaikat:issue#29600
Open

berasaikat wants to merge 8 commits into
scikit-learn:mainfrom
berasaikat:issue#29600

Conversation

@berasaikat

Copy link
Copy Markdown

Description

Closes #29600.

This PR adds three new loss functions to SGDRegressor — 'poisson', 'gamma', and 'tweedie' — enabling online/incremental learning of Generalized Linear Models (GLMs) that are currently only available as batch estimators (PoissonRegressor, GammaRegressor, TweedieRegressor).

This is particularly useful for large datasets that don't fit in memory, where partial_fit is the only viable training strategy.


Motivation

PoissonRegressor, GammaRegressor, and TweedieRegressor are widely used in industry for count data, insurance pricing, and other non-negative target problems. However, none of them support partial_fit. The only way to do incremental regression in scikit-learn today is via SGDRegressor, which was missing these loss functions.

As noted in #29600, workarounds like learning in log-space with squared loss fail when targets include zeros — Poisson regression handles this gracefully.


Usage Example

import numpy as np
from sklearn.linear_model import SGDRegressor

rng = np.random.RandomState(42)
X = rng.randn(10_000, 10)
y = np.exp(X @ rng.randn(10))   # positive targets from a log-linear model

# Incremental Poisson regression — equivalent to online PoissonRegressor
reg = SGDRegressor(loss="poisson", learning_rate="constant", eta0=0.01)
reg.fit(X, y)
y_pred = np.exp(reg.predict(X))   # log-link: output is log(mu)

# Incremental Tweedie regression with power=1.5
reg_tw = SGDRegressor(loss="tweedie", power=1.5, learning_rate="constant", eta0=0.01)
reg_tw.fit(X, y)

# Works with partial_fit for true online learning
reg_online = SGDRegressor(loss="poisson")
for X_batch, y_batch in zip(np.array_split(X, 100), np.array_split(y, 100)):
    reg_online.partial_fit(X_batch, y_batch)

Checklist

  • [ x] Added unit tests for all new loss functions (loss values, gradients, pickle)
  • [x ] Added integration tests (fit, partial_fit, invalid power)
  • [ x] check_estimator(SGDRegressor()) passes
  • [x ] Pre-commit passes
  • [ x] Changelog entry added
  • [x ] Docstring updated for loss and power parameters
  • [x ] doc/modules/sgd.rst updated

@virchan virchan added the autoclose PR automatically closed 14 days after setting the label label Apr 21, 2026
@github-actions

Copy link
Copy Markdown

⏰ This pull request might be automatically closed in two weeks from now.

Thank you for your contribution to scikit-learn and for the effort you have put into this PR. This pull request does not yet meet the quality and clarity needed for an effective review. Project maintainers have limited time for code reviews, and our goal is to prioritize well-prepared contributions to keep scikit-learn maintainable.

To increase the chance of a productive review, please refer to: How do I improve my issue or pull request? As the author, you are responsible for driving this PR, which entails doing necessary background research as well as presenting its context and your thought process. If you are a new contributor, or do not know how to fulfill these requirements, we recommend that you familiarise yourself with scikit-learn's development conventions via other contribution types (e.g., reviewing PRs) before submitting code.

Scikit-learn maintainers cannot provide one-to-one guidance on this PR. However, if you ask focused, well-researched questions, a community member may be willing to help. 💬

If you substantially improve this PR within two weeks, a team member may remove the autoclose label and the PR stays open. Cosmetic changes or incomplete fixes will not be sufficient. Maintainers will assess improvements on their own schedule. Please do not ping (@) maintainers.

@berasaikat

Copy link
Copy Markdown
Author

All CI check passed. Happy to make any changes if there's feedback.

@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown

Thank you for your interest in contributing to scikit-learn, but we cannot accept your contribution as this pull request does not meet our development standards.

Following our autoclose policy, we are closing this PR after allowing two weeks time for improvements.

Thank you for your understanding. If you think your PR has been closed by mistake, please comment below.

@github-actions github-actions Bot closed this May 6, 2026
@jeremiedbb jeremiedbb reopened this May 6, 2026
@jeremiedbb jeremiedbb removed the autoclose PR automatically closed 14 days after setting the label label May 6, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Please extend the loss-functions in SGDRegressor to allow incremental learning of Poisson / Gamma / Tweedie regressors

3 participants