Skip to content

Commit 77f097b

Browse files
amy12xxglemaitre
authored andcommitted
DOC simplify SVM margin illustration by chaging plotting style (#19387)
1 parent f9ec9f7 commit 77f097b

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

examples/svm/plot_svm_margin.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import numpy as np
2626
import matplotlib.pyplot as plt
27+
from matplotlib import cm
2728
from sklearn import svm
2829

2930
# we create 40 separable points
@@ -62,8 +63,9 @@
6263
plt.plot(xx, yy_up, 'k--')
6364

6465
plt.scatter(clf.support_vectors_[:, 0], clf.support_vectors_[:, 1], s=80,
65-
facecolors='none', zorder=10, edgecolors='k')
66-
plt.scatter(X[:, 0], X[:, 1], c=Y, zorder=10, cmap=plt.cm.Paired,
66+
facecolors='none', zorder=10, edgecolors='k',
67+
cmap=cm.get_cmap('RdBu'))
68+
plt.scatter(X[:, 0], X[:, 1], c=Y, zorder=10, cmap=cm.get_cmap('RdBu'),
6769
edgecolors='k')
6870

6971
plt.axis('tight')
@@ -72,13 +74,13 @@
7274
y_min = -6
7375
y_max = 6
7476

75-
XX, YY = np.mgrid[x_min:x_max:200j, y_min:y_max:200j]
76-
Z = clf.predict(np.c_[XX.ravel(), YY.ravel()])
77+
YY, XX = np.meshgrid(yy, xx)
78+
xy = np.vstack([XX.ravel(), YY.ravel()]).T
79+
Z = clf.decision_function(xy).reshape(XX.shape)
7780

78-
# Put the result into a color plot
79-
Z = Z.reshape(XX.shape)
80-
plt.figure(fignum, figsize=(4, 3))
81-
plt.pcolormesh(XX, YY, Z, cmap=plt.cm.Paired)
81+
# Put the result into a contour plot
82+
plt.contourf(XX, YY, Z, cmap=cm.get_cmap('RdBu'),
83+
alpha=0.5, linestyles=['-'])
8284

8385
plt.xlim(x_min, x_max)
8486
plt.ylim(y_min, y_max)

0 commit comments

Comments
 (0)