Skip to content

fix(metrics): correct inverted log-term sign in GammaDeviance - #427

Open
ChrisW09 wants to merge 1 commit into
mainfrom
fix/gamma-deviance-sign
Open

fix(metrics): correct inverted log-term sign in GammaDeviance#427
ChrisW09 wants to merge 1 commit into
mainfrom
fix/gamma-deviance-sign

Conversation

@ChrisW09

Copy link
Copy Markdown
Collaborator

Fixes #417

Problem

GammaDeviance computed 2*mean(log(y/mu) + (y-mu)/mu) instead of the gamma deviance 2*mean(log(mu/y) + y/mu - 1).

Both forms are 0 at mu == y, so the existing perfect-prediction test passed. For any imperfect prediction it disagrees with sklearn.metrics.mean_gamma_deviance (0.341 vs 0.135 on a small example), and the metric is unbounded below: predicting mu = 1000*y scores -14.6, so it rewards unbounded over-prediction. It is the primary metric for lss:gamma in METRIC_REGISTRY, so HPO and model selection minimizing it were driven toward degenerate over-predicting models.

Fix

One-line sign correction in deeptab/metrics/distributional.py.

Tests

  • test_gamma_deviance_matches_sklearn — compares against sklearn on imperfect predictions (a perfect-prediction test cannot detect a sign error).
  • test_gamma_deviance_nonnegative_for_overprediction — deviance must stay positive for extreme over-prediction.

Full tests/test_metrics.py passes (202 tests).

🤖 Generated with Claude Code

The deviance computed 2*mean(log(y/mu) + (y-mu)/mu) instead of
2*mean(log(mu/y) + y/mu - 1). Both forms are 0 at mu == y, so the
existing perfect-prediction test passed, but for any imperfect
prediction the metric disagreed with sklearn's mean_gamma_deviance and
was unbounded below: predicting mu = 1000*y scored -14.6, i.e. the
metric rewarded unbounded over-prediction. It is the primary metric for
lss:gamma, so HPO and model selection were driven toward degenerate
models.

Adds a test comparing against sklearn on imperfect predictions (a
perfect-prediction test cannot detect a sign error) and a
non-negativity test for extreme over-prediction.

Fixes #417

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

[BUG] GammaDeviance log-term sign is inverted — metric is unbounded below and rewards over-prediction

1 participant