fix(metrics): count confidence 1.0 in ECE and stop thresholding 1-D integer labels - #428
Open
ChrisW09 wants to merge 1 commit into
Open
fix(metrics): count confidence 1.0 in ECE and stop thresholding 1-D integer labels#428ChrisW09 wants to merge 1 commit into
ChrisW09 wants to merge 1 commit into
Conversation
…nteger labels ExpectedCalibrationError used half-open bins everywhere, including the last one, so samples at confidence exactly 1.0 (saturated softmax, or hard labels passed as probabilities) fell into no bin: a model that is always wrong at 100% confidence scored a perfect ECE of 0. The final bin is now right-inclusive. Accuracy and F1Score thresholded any 1-D input at 0.5 despite documenting 1-D integer-label support, mangling multiclass labels (label 2 -> 1). Accuracy()([0,1,2,2], [0,1,2,2]) -- perfect predictions -- returned 0.5. 1-D integer-valued input is now treated as labels; only fractional 1-D scores are thresholded, so binary probability inputs keep working. Fixes #421 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Collaborator
Author
|
CI note: the two red test jobs on this PR ( They are a pre-existing flake: |
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.
Fixes #421
Problems
ExpectedCalibrationErrorignores confidence == 1.0. Every bin was half-open[lo, hi), including the last[0.9, 1.0), so predictions at exactly 1.0 fell into no bin and contributed 0. A model predicting the wrong class with probability 1.0 on every sample — the worst possible calibration — scored ECE = 0.0.Accuracy/F1Scorebinarize 1-D input at 0.5. The docstrings promise 1-D integer-label support, but any 1-D input was thresholded, mangling multiclass labels (label 2 → 1).Accuracy()([0,1,2,2], [0,1,2,2])returned 0.5 for perfect predictions. This bites the natural compositionAccuracy()(y, model.predict(X)), sincepredictreturns 1-D labels.Fix
_labels_from_predictionshelper: 2-D input → argmax, 1-D integer-valued input → labels as-is, 1-D fractional input → thresholded at 0.5 (so binary probability scores keep working).Tests
test_ece_counts_full_confidence,test_accuracy_1d_multiclass_labels,test_f1_1d_multiclass_labels. Fulltests/test_metrics.pypasses.🤖 Generated with Claude Code