Skip to content

FIX Use uniform probabilities for zero-affinity rows - #34835

Open
sudam802 wants to merge 2 commits into
scikit-learn:mainfrom
sudam802:fix/label-propagation-zero-affinity
Open

FIX Use uniform probabilities for zero-affinity rows#34835
sudam802 wants to merge 2 commits into
scikit-learn:mainfrom
sudam802:fix/label-propagation-zero-affinity

Conversation

@sudam802

Copy link
Copy Markdown

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:

  • python -m pytest sklearn/semi_supervised/tests/test_label_propagation.py -q (175 passed, 60 skipped)
  • python -m ruff check sklearn/semi_supervised/_label_propagation.py sklearn/semi_supervised/tests/test_label_propagation.py
  • python -m ruff format --check sklearn/semi_supervised/_label_propagation.py sklearn/semi_supervised/tests/test_label_propagation.py

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:

  • Code generation
  • Test generation
  • Research and understanding

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.

@github-actions

Copy link
Copy Markdown

Thank you for opening your first pull request to scikit-learn! πŸŽ‰

To help get your contribution reviewed, please make sure that:

  • You have filled out the pull request template.

  • The pull request addresses an existing issue that is ready for contribution (e.g. not tagged as 'Needs Triage', 'Needs Decision', ...). If you are proposing a new feature, please open an issue to discuss it first.

  • There are no other open pull requests already targeting the same issue.

  • You have followed the pull request checklist. In particular, linting and tests should pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reconsider zero-affinity row fallback in LabelPropagation/LabelSpreading (fit + predict_proba) to mathematically valid probability distributions

1 participant