Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### 決定境界の可視化
- import matplotlib.pyplot as plt
- # Parameters for plot
- n_classes = 2
- plot_colors = "br"
- plot_step = 0.05
- #グラフ描画時の説明変数 x、yの最大値&最小値を算出。
- #グラフ描画のメッシュを定義
- x_min, x_max = data_array[:, 0].min() - 1, data_array[:, 0].max() + 1
- y_min, y_max = data_array[:, 1].min() - 1, data_array[:, 1].max() + 1
- xx, yy = np.meshgrid(np.arange(x_min, x_max, plot_step),
- np.arange(y_min, y_max, plot_step))
- #各メッシュ上での決定木による分類を計算
- Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
- Z = Z.reshape(xx.shape)
- #決定木による分類を等高線フィールドプロットでプロット
- cs = plt.contour(xx, yy, Z, cmap=plt.cm.Paired)
- plt.xlabel('x')
- plt.ylabel('y')
- plt.axis("tight")
- #教師データも重ねてプロット
- for i, color in zip(range(n_classes), plot_colors):
- idx = np.where(class_array == i)
- plt.scatter(data_array[idx, 0], data_array[idx, 1], c=color, label=['a','b'],
- cmap=plt.cm.Paired)
- plt.axis("tight")
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement