|
24 | 24 |
|
25 | 25 | import numpy as np
|
26 | 26 | import matplotlib.pyplot as plt
|
| 27 | +from matplotlib import cm |
27 | 28 | from sklearn import svm
|
28 | 29 |
|
29 | 30 | # we create 40 separable points
|
|
62 | 63 | plt.plot(xx, yy_up, 'k--')
|
63 | 64 |
|
64 | 65 | 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'), |
67 | 69 | edgecolors='k')
|
68 | 70 |
|
69 | 71 | plt.axis('tight')
|
|
72 | 74 | y_min = -6
|
73 | 75 | y_max = 6
|
74 | 76 |
|
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) |
77 | 80 |
|
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=['-']) |
82 | 84 |
|
83 | 85 | plt.xlim(x_min, x_max)
|
84 | 86 | plt.ylim(y_min, y_max)
|
|
0 commit comments