Repository navigation
fix: check the Tweedie deviance domain for each power - #295
Open
Raashish Aggarwal (raashish1601) wants to merge 1 commit into
Open
Raashish Aggarwal (raashish1601) wants to merge 1 commit into
Raashish Aggarwal (raashish1601) wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
tweedie_deviancechecks that every prediction is strictly positive, whatever the power. Withpower=0the deviance is just the squared error, so zero or negative predictions are valid there, but they raise:The opposite happens for
1 <= power < 2: a negative target is not checked, so it is silently scored. Withpower=1.5the general branch clips the target at 0 and returns a negative deviance (-0.70 fory=[1, -2, 0.5],model=[0.5, 1, 2]), and withpower=1the 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=0accepts non-positive predictions and matches the mean squared error (pandas and polars), and one thatpower1 and 1.5 reject a negative target. Both fail on main.tests/test_losses.pypasses locally, and ruff format and mypy pass on the changed files.