Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. ### 決定境界の可視化
  2. import matplotlib.pyplot as plt
  3.  
  4. # Parameters for plot
  5. n_classes = 2
  6. plot_colors = "br"
  7. plot_step = 0.05
  8.  
  9. #グラフ描画時の説明変数 x、yの最大値&最小値を算出。
  10. #グラフ描画のメッシュを定義
  11. x_min, x_max = data_array[:, 0].min() - 1, data_array[:, 0].max() + 1
  12. y_min, y_max = data_array[:, 1].min() - 1, data_array[:, 1].max() + 1
  13. xx, yy = np.meshgrid(np.arange(x_min, x_max, plot_step),
  14. np.arange(y_min, y_max, plot_step))
  15. #各メッシュ上での決定木による分類を計算
  16. Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
  17. Z = Z.reshape(xx.shape)
  18.  
  19. #決定木による分類を等高線フィールドプロットでプロット
  20. cs = plt.contour(xx, yy, Z, cmap=plt.cm.Paired)
  21. plt.xlabel('x')
  22. plt.ylabel('y')
  23. plt.axis("tight")
  24.  
  25. #教師データも重ねてプロット
  26. for i, color in zip(range(n_classes), plot_colors):
  27. idx = np.where(class_array == i)
  28. plt.scatter(data_array[idx, 0], data_array[idx, 1], c=color, label=['a','b'],
  29. cmap=plt.cm.Paired)
  30. plt.axis("tight")
  31.  
  32. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement