FIX Use uniform probabilities for zero-affinity rows - #34835
Open
sudam802 wants to merge 2 commits into
Open
Conversation
|
Thank you for opening your first pull request to scikit-learn! π To help get your contribution reviewed, please make sure that:
|
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.
Reference Issues/PRs
Fixes #34351. Related to #34350.
What does this implement/fix? Explain your changes.
Zero-affinity rows currently normalize to all-zero values during fit and can produce NaN values in predict_proba. Neither result is a valid categorical probability distribution.
This change introduces one private normalization helper shared by fit and predict_proba. Rows with a nonzero sum retain the existing normalization, while zero-sum rows receive uniform probabilities. The uniform fallback represents the absence of class information without preferring a class and follows the direction agreed in #34351.
Regression tests cover disconnected training samples and far-away prediction samples for both LabelPropagation and LabelSpreading.
Tests:
Introduce yourself
I am contributing this focused numerical correctness fix after following the maintainer-approved direction in #34351.
AI usage disclosure
I used AI assistance for:
Any other comments?
The main review point is applying the uniform fallback during LabelPropagation iterations as well as final normalization. This keeps disconnected rows valid throughout fitting and is covered by the existing closed-form and convergence tests.
This pull request includes code written with the assistance of AI.
The code has not yet been reviewed by a human.