Repository navigation
FIX max int64-safe scale for skewed tiny sample weights - #25
Merged
ogrisel merged 2 commits intoAug 31, 2026
Merged
Conversation
Mean-based adaptive scale (~1e6 / mean(weight)) still rounds minority tiny weights to zero when most weights are O(1). Choose the largest scale such that n * max(weight) * scale fits in int64 (clipped to int64 max when n * max(weight) < 1), and extend the float32-only test with a skewed_tiny_top case that fails under the mean-based scheme. Also fixes ruff RUF046 from the previous adaptive-scale change. Co-authored-by: Olivier Grisel <[email protected]>
Drop the skewed_tiny_top special-case size so the parametrized test always covers n_pos > 2**24 with a single sample count. Co-authored-by: Olivier Grisel <[email protected]>
ogrisel
marked this pull request as ready for review
August 31, 2026 07:56
ogrisel
merged commit Aug 31, 2026
f57222f
into
fix-34813-cmat-weighted-int-scale
18 of 19 checks passed
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.
Follow-up to the mean-based adaptive scale (merged from #24 into this branch / upstream scikit-learn#34827), addressing Fazel94's latest comment.
Why the previous adaptive scale was still wrong
Mean-based
scale ≈ 1e6 * n / weight.sum()works when all weights are small (pre-normalized / uniformly tiny), but fails when weights are skewed:w = 1e-8, rest havew = 1.01.11e6round(1e-8 * scale) = 0→ early-curvetpsare exactly 0 while the float64 reference is ≈4.5e-3Final
tps[-1]can still look fine because most mass uses weight 1.0 — so end-point-only tests miss this.Fix
Use the largest int64-safe scale from max weight (as suggested in the review):
Also removes the
int(round(...))that triggered ruff RUF046 on the linter CI for scikit-learn#34827.Tests
Extended
test_confusion_matrix_at_thresholds_float32_only_weighted_large_nwithskewed_tiny_top(samen_samples=20_000_000as the other kinds):1e-8weightstps_ref < 1) tightly against float64 and requirestps > 0All five parametrizations pass locally (
uniform,variable,normalized,tiny,skewed_tiny_top).This pull request includes code written with the assistance of AI.
The code has not yet been reviewed by a human.