Skip to content

DOC: Consolidated density-based clustering examples - #32228

Open
j-hendricks wants to merge 7 commits into
scikit-learn:mainfrom
j-hendricks:doc/consolidate-density-clustering-docs
Open

j-hendricks wants to merge 7 commits into
scikit-learn:mainfrom
j-hendricks:doc/consolidate-density-clustering-docs

Conversation

@j-hendricks

@j-hendricks j-hendricks commented Sep 20, 2025 •

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Fixes #29962. Completes closed PR #31102.

What does this implement/fix? Explain your changes.

Consolidates 3 related example docs (DBSCAN, HDBSCAN, and OPTICS) into one concise example.

Follows advice from ArturoAmorQ, namely using only one dataset for conciseness.

Removes detailed explanations of algorithm design as these are already explained in the user guide.

Any other comments?

Builds upon original PR #31102 and uses much of the original explanation and code authored by daustria. Therefore, I have added them as a co-author.

@github-actions

Copy link
Copy Markdown

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 9fd0ec0. Link to the linter CI: here

@j-hendricks j-hendricks changed the title Consolidated density-based clustering examples DOC: Consolidated density-based clustering examples Sep 21, 2025

@mcvincekova mcvincekova 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.

Overall example looks well-structured.

Only have minor suggestions for the helper plot function.

# Remove black and use for noise instead.
unique_labels = set(labels)

colors = [plt.cm.Spectral(each) for each in np.linspace(0, 1, len(set(labels)))]

@mcvincekova mcvincekova Jul 18, 2026 •

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.

[Minor] Reuse a predefined variable.

Suggested change
colors = [plt.cm.Spectral(each) for each in np.linspace(0, 1, len(set(labels)))]
colors = [plt.cm.Spectral(each) for each in np.linspace(0, 1, len(unique_labels))]

markeredgecolor="black",
alpha=0.5 if k == -1 else 0.1 + 0.9 * proba_map[ci],
)
n_clusters_ = len(set(labels)) - (1 if -1 in labels else 0)

@mcvincekova mcvincekova Jul 18, 2026 •

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.

[Minor] Resue a predefined variable.

Suggested change
n_clusters_ = len(set(labels)) - (1 if -1 in labels else 0)
n_clusters_ = len(unique_labels) - (1 if -1 in labels else 0)

"x" if k == -1 else "o",
markerfacecolor=tuple(col),
markeredgecolor="black",
alpha=0.5 if k == -1 else 0.1 + 0.9 * proba_map[ci],

@mcvincekova mcvincekova Jul 18, 2026 •

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.

[Suggestion] Remove proba_map entirely, since as far as I can see it only adds extra overhead (?). The mapping in the dictionary still relies on the original indexes of the array anyhow.

Suggested change
alpha=0.5 if k == -1 else 0.1 + 0.9 * proba_map[ci],
alpha=0.5 if k == -1 else 0.1 + 0.9 * probabilities[ci],

@StefanieSenger

StefanieSenger commented Jul 19, 2026 •

Copy link
Copy Markdown
Member

Hello @j-hendricks, this review was a contribution of a participant in the EuroPython/EuroScipy scikit-learn sprint.

Happy to help in the process of consolidating this PR as well. :)

@j-hendricks
j-hendricks force-pushed the doc/consolidate-density-clustering-docs branch from 6980a99 to 1b3e5b0 Compare July 26, 2026 16:27
@j-hendricks

Copy link
Copy Markdown
Contributor Author

@mcvincekova thank you for the feedback. I agree with the suggestions you made and have incorporated them into the PR. I have fixed some formatting issues as well.

@StefanieSenger if you wouldn't mind taking a look at the rendered doc, that would also be greatly appreciated :)

Only remaining issue I see: at the end of the page it says "Total running time of the script:" followed by a time measurement. I have no idea what code is causing that to render and would like to remove it before merging

@mcvincekova mcvincekova 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.

@j-hendricks imho looks good. Thanks for addressing the comments.

This branch has not been deployed

No deployments
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.

DOC merging the examples related to OPTICS, DBSCAN, and HDBSCAN

4 participants