Repository navigation
DOC fix colors and add support vectors in SVC with iris dataset example - #33892
Conversation
virchan
left a comment
There was a problem hiding this comment.
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.
| # 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", | ||
| ) |
There was a problem hiding this comment.
Compared to main branch, this does not seem to add anything visually. Did you overlook something?
There was a problem hiding this comment.
I double checked:
This is the current version on main

and this is the figure from this PR

So, apart from the color fix, the second version also does not plot all data points but only the support vectors.
There was a problem hiding this comment.
Now I get it. But why should we plot only the support vectors points?
There was a problem hiding this comment.
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

but then it would make sense to change the colors, because the white-ish points become hard to see.
There was a problem hiding this comment.
I guess it adds value, it shows how to plot the support vectors.
Reference Issues/PRs
Towards #33557
What does this implement/fix? Explain your changes.
Update color selection to use
multiclass_colorsinstead ofcmap.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:
Any other comments?