Repository navigation
Conversation
gini() sorted rows with argsort and did not handle ties, so the score depended on input row order: a constant prediction could score 1.0 or -1.0. Give rows in a tie the group's mean target. Untied input gives the same result as before. Add tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Proposed changes
gini(y, p)incausalml/metrics/regression.pysorts rows bypwithargsortand does not handle ties, so when predictions tie the score depends on the input row order:A constant prediction gets a perfect score. Ties are common with binary or rounded predictions, and
regression_metricsreports Gini by default.The fix sorts with a stable sort and gives every row in a group of tied keys the group's mean
y, so ties no longer depend on row order. With no ties the result is unchanged (same value to full precision on a 500-row random check).Types of changes
Checklist
Further comments
Tests in
tests/test_metrics.py: a constant prediction gives 0 in both row orders (fails on master), a perfect prediction still gives 1, and untied data gives the same value as before.black --checkpasses.I used Claude to help find and fix this, and reviewed and tested the change myself.