|
22 | 22 |
|
23 | 23 | # Parameters
|
24 | 24 | n_classes = 3
|
25 |
| -plot_colors = "bry" |
| 25 | +plot_colors = "ryb" |
26 | 26 | plot_step = 0.02
|
27 | 27 |
|
28 | 28 | # Load data
|
|
44 | 44 | y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
|
45 | 45 | xx, yy = np.meshgrid(np.arange(x_min, x_max, plot_step),
|
46 | 46 | np.arange(y_min, y_max, plot_step))
|
| 47 | + plt.tight_layout(h_pad=0.5, w_pad=0.5, pad=2.5) |
47 | 48 |
|
48 | 49 | Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
|
49 | 50 | Z = Z.reshape(xx.shape)
|
50 |
| - cs = plt.contourf(xx, yy, Z, cmap=plt.cm.Paired) |
| 51 | + cs = plt.contourf(xx, yy, Z, cmap=plt.cm.RdYlBu) |
51 | 52 |
|
52 | 53 | plt.xlabel(iris.feature_names[pair[0]])
|
53 | 54 | plt.ylabel(iris.feature_names[pair[1]])
|
54 |
| - plt.axis("tight") |
55 | 55 |
|
56 | 56 | # Plot the training points
|
57 | 57 | for i, color in zip(range(n_classes), plot_colors):
|
58 | 58 | idx = np.where(y == i)
|
59 | 59 | plt.scatter(X[idx, 0], X[idx, 1], c=color, label=iris.target_names[i],
|
60 |
| - cmap=plt.cm.Paired) |
61 |
| - |
62 |
| - plt.axis("tight") |
| 60 | + cmap=plt.cm.RdYlBu, edgecolor='black', s=15) |
63 | 61 |
|
64 | 62 | plt.suptitle("Decision surface of a decision tree using paired features")
|
65 |
| -plt.legend() |
| 63 | +plt.legend(loc='lower right', borderpad=0, handletextpad=0) |
| 64 | +plt.axis("tight") |
66 | 65 | plt.show()
|
0 commit comments