Skip to content

DOC fix colors and add support vectors in SVC with iris dataset example - #33892

Merged
lorentzenchr merged 1 commit into
scikit-learn:mainfrom
AnneBeyer:dbd_fix_colors_plot_iris_svc
May 6, 2026
Merged

lorentzenchr merged 1 commit into
scikit-learn:mainfrom
AnneBeyer:dbd_fix_colors_plot_iris_svc

Conversation

@AnneBeyer

Copy link
Copy Markdown
Member

Reference Issues/PRs

Towards #33557

What does this implement/fix? Explain your changes.

Update color selection to use multiclass_colors instead of cmap.
A comment in the code said that support vectors will be plotted, but the whole dataset was plotted in all cases instead, so I also adapted that to only plot the respective support vectors.

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?

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

Overall, LGTM.

Just a minor request, @AnneBeyer: since you're already updating the comments in the code, it might be worth going a bit further and making the example more notebook-like.

You can refer to this example.

@AnneBeyer

Copy link
Copy Markdown
Member Author

Thank you @virchan! I noticed this in some of the examples in #33557, but I would rather keep the changes focussed on the content here and leave the notebook styling for a follow-up refactoring.

@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! Thanks, @AnneBeyer!

@virchan virchan added Quick Review For PRs that are quick to review Waiting for Second Reviewer First reviewer is done, need a second one! labels May 1, 2026
Comment on lines +87 to +101
# Plot the support vectors.
# For LinearSVC we compute the support vectors from the decision function, see
# https://scikit-learn.org/dev/auto_examples/svm/plot_linearsvc_support_vectors.html
if hasattr(clf, "support_"):
support_vector_indices = clf.support_
else:
decision_function = clf.decision_function(X)
support_vector_indices = (np.abs(decision_function) <= 1 + 1e-15).nonzero()[0]
ax.scatter(
X[support_vector_indices, 0],
X[support_vector_indices, 1],
c=y[support_vector_indices],
cmap=plt.cm.coolwarm,
edgecolors="k",
)

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.

Compared to main branch, this does not seem to add anything visually. Did you overlook something?

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 double checked:
This is the current version on main
image

and this is the figure from this PR
image

So, apart from the color fix, the second version also does not plot all data points but only the support vectors.

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.

Now I get it. But why should we plot only the support vectors points?

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.

Because the dataset is the same in all four cases, but the support vectors differ, depending on the selected kernel function. I thought about adding a highlighting instead as in #33891 like this
image
but then it would make sense to change the colors, because the white-ish points become hard to see.

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.

I guess it adds value, it shows how to plot the support vectors.

@jeremiedbb jeremiedbb removed the Waiting for Second Reviewer First reviewer is done, need a second one! label May 4, 2026
@lorentzenchr
lorentzenchr merged commit 2bd4861 into scikit-learn:main May 6, 2026
51 of 52 checks passed
@AnneBeyer
AnneBeyer deleted the dbd_fix_colors_plot_iris_svc branch June 4, 2026 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants