Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX: avoid EfficiencyWarning in OPTICS with metric='precomputed' - #34692

Merged
virchan merged 10 commits into
scikit-learn:mainfrom
DeaMariaLeon:optics
Sep 4, 2026
Merged

FIX: avoid EfficiencyWarning in OPTICS with metric='precomputed'#34692
virchan merged 10 commits into
scikit-learn:mainfrom
DeaMariaLeon:optics

Conversation

@DeaMariaLeon

@DeaMariaLeon DeaMariaLeon commented Aug 10, 2026

Copy link
Copy Markdown
Member

Reference Issues/PRs

Fixes #34647

What does this implement/fix? Explain your changes.

The issue and fix are the same as #34399:
OPTICS needs each point to count as its own neighbour. So, for sparse input, the diagonal has to be made explicit.

scikit-learn uses scipy's setdiag to insert the point which un-sorts the sparse matrix that had already been sorted and emits a warning. To remove the warning (because points are not sorted), we need to call sort_graph_by_row_values after the call to setdiag.

Note: The fix removes the EfficiencyWarning for every sparse precomputed input to OPTICS.fit. A user who passes an unsorted graph gets no warning either.
This is matching #34399 behaviour.

AI usage disclosure

I used AI assistance for:

  • Research and understanding
  • test

Any other comments?

@DeaMariaLeon DeaMariaLeon moved this to In progress in Labs Aug 10, 2026
@ogrisel ogrisel removed this from Labs Aug 10, 2026
@DeaMariaLeon DeaMariaLeon moved this to In progress in Labs Aug 11, 2026
# own neighbor
X.setdiag(X.diagonal())
# Sorting could be undone by .setdiag(), make sure it's sorted
X = sort_graph_by_row_values(X, warn_when_not_sorted=False)

@DeaMariaLeon DeaMariaLeon Aug 11, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: The fix removes the EfficiencyWarning for every sparse precomputed input to OPTICS.fit. A user who passes an unsorted graph doesn't get a warning either.
This matches #34399 behaviour.

@DeaMariaLeon
DeaMariaLeon marked this pull request as ready for review August 11, 2026 07:30
@DeaMariaLeon DeaMariaLeon moved this from In progress to PR waiting for reviews in Labs Aug 17, 2026
@DeaMariaLeon

Copy link
Copy Markdown
Member Author

@betatim you reviewed a very similar PR (#34399).
I wonder if you have time/interest to review this one. If not, that's fine too.

@DeaMariaLeon

Copy link
Copy Markdown
Member Author

Friendly ping @cakedev0 in case this was forgotten

@cakedev0 cakedev0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@DeaMariaLeon

Copy link
Copy Markdown
Member Author

Thank you!

@DeaMariaLeon DeaMariaLeon added the Waiting for Second Reviewer First reviewer is done, need a second one! label Sep 1, 2026

@virchan virchan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you everyone for your time!

@virchan
virchan merged commit af6b2de into scikit-learn:main Sep 4, 2026
46 checks passed
@github-project-automation github-project-automation Bot moved this from PR waiting for reviews to Done in Labs Sep 4, 2026
@DeaMariaLeon
DeaMariaLeon deleted the optics branch September 4, 2026 06:50
@DeaMariaLeon

Copy link
Copy Markdown
Member Author

Thank you @virchan!

cboseak pushed a commit to cboseak/scikit-learn that referenced this pull request Sep 4, 2026
prady0t pushed a commit to prady0t/scikit-learn that referenced this pull request Sep 6, 2026
@jeremiedbb jeremiedbb mentioned this pull request Sep 8, 2026
14 tasks
jeremiedbb pushed a commit to jeremiedbb/scikit-learn that referenced this pull request Sep 8, 2026
jeremiedbb pushed a commit to jeremiedbb/scikit-learn that referenced this pull request Sep 8, 2026
jeremiedbb pushed a commit to jeremiedbb/scikit-learn that referenced this pull request Sep 8, 2026
jeremiedbb pushed a commit to jeremiedbb/scikit-learn that referenced this pull request Sep 9, 2026
jeremiedbb pushed a commit to jeremiedbb/scikit-learn that referenced this pull request Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:cluster Waiting for Second Reviewer First reviewer is done, need a second one!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OPTICS always triggers and EfficiencyWarning

4 participants