Skip to content

fix: check the Tweedie deviance domain for each power - #295

Open
Raashish Aggarwal (raashish1601) wants to merge 1 commit into
Nixtla:mainfrom
raashish1601:fix/tweedie-deviance-domain
Open

Raashish Aggarwal (raashish1601) wants to merge 1 commit into
Nixtla:mainfrom
raashish1601:fix/tweedie-deviance-domain

Conversation

@raashish1601

Copy link
Copy Markdown

tweedie_deviance checks that every prediction is strictly positive, whatever the power. With power=0 the deviance is just the squared error, so zero or negative predictions are valid there, but they raise:

df = pd.DataFrame({"unique_id": ["a"] * 3, "y": [1.0, -2.0, 0.5], "model": [0.5, -1.0, 0.0]})
tweedie_deviance(df, ["model"], power=0)
# ValueError: All predictions must be strictly positive for Tweedie deviance.

The opposite happens for 1 <= power < 2: a negative target is not checked, so it is silently scored. With power=1.5 the general branch clips the target at 0 and returns a negative deviance (-0.70 for y=[1, -2, 0.5], model=[0.5, 1, 2]), and with power=1 the log term is dropped for that row.

The checks now follow the domain of each power, the same as sklearn.metrics.mean_tweedie_deviance:

  • power=0: any target and prediction.
  • 1 <= power < 2: target must be non-negative (new check), prediction strictly positive.
  • power >= 2: target and prediction strictly positive (unchanged).

Tests: added one test that power=0 accepts non-positive predictions and matches the mean squared error (pandas and polars), and one that power 1 and 1.5 reject a negative target. Both fail on main. tests/test_losses.py passes locally, and ruff format and mypy pass on the changed files.

@CLAassistant

CLAassistant commented Oct 6, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants