Skip to content

DOC Use DecisionBoundaryDisplay colors for scatter in Nearest Neighbors Classification example - #33849

Merged
jeremiedbb merged 2 commits into
scikit-learn:mainfrom
AnneBeyer:dbd_update_scatter_colors
Apr 24, 2026
Merged

jeremiedbb merged 2 commits into
scikit-learn:mainfrom
AnneBeyer:dbd_update_scatter_colors

Conversation

@AnneBeyer

Copy link
Copy Markdown
Member

Reference Issues/PRs

Towards #33557

What does this implement/fix? Explain your changes.

Re-use colors from the DecisionBoundaryDisplay for the scatter plot in the Nearest Neighbors Classification example.
I also moved the legend to the right because the difference around the blue data point was almost covered by the legend.

AI usage disclosure

I used AI assistance for:

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Any other comments?

scatter = disp.ax_.scatter(X.iloc[:, 0], X.iloc[:, 1], c=y, edgecolors="k")
cmap = mpl.colors.ListedColormap(disp.multiclass_colors_)
scatter = disp.ax_.scatter(
X.iloc[:, 0], X.iloc[:, 1], c=y, cmap=cmap, edgecolors="k"

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.

I think it would make more sense to also only plot the training portion of X here, or mark train and test data points differently, or simply use all data for fitting the classifier. X_test is only used for deriving the grid boundaries in the DecisionBoundaryDisplay, but I will come back to this once #33094 is addressed.

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.

The decision regions would be same, so maybe it's just to not have too many points, or to show the generalisation capability so the decision on the test set. Mixing both, represented differently, might make the plot less readable.

@jeremiedbb jeremiedbb 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. Thanks

@jeremiedbb
jeremiedbb merged commit 9db12f0 into scikit-learn:main Apr 24, 2026
36 checks passed
@AnneBeyer
AnneBeyer deleted the dbd_update_scatter_colors branch June 4, 2026 10:48
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.

2 participants