Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. import numpy as np
  2. import juputer
  3. import sklearn
  4. import pandas as pd
  5. import matplotlib.pyplot as plt
  6. import dateset
  7.  
  8. from SVM import svmlib
  9. from sklearn.tree import DecisionTreeReqressor
  10. from sklear.tree import export_graphviz
  11. from sklearn.datasets import load_iris
  12. from sklearn import tree
  13.  
  14. #Инициализируем и распетываем набор данных
  15. datasetx = np.array(
  16. [[0],
  17. [2],
  18. [4],
  19. [6],
  20. [8],
  21. [10],
  22. [12],
  23. [14]])
  24. #print(datasetx)
  25. datasety = np.array(
  26. [[0],
  27. [0.92],
  28. [0.94],
  29. [0.96],
  30. [0.98],
  31. [1.00]])
  32. #print(datasety)
  33.  
  34. #Выбираем строки и столбцы
  35. x = datasetx[:, 1:2].astype(int)
  36. y = datasety[:, 1:2].astype(int)
  37. #print(x)
  38.  
  39. #Регрессор древа решений
  40. regressor = DecisionTreeReqressor(random_state = 0)
  41. regressor. fit(x, y)
  42.  
  43. #Визуализация результата
  44. x_grid = np.arange(min(x), max(x), 0.01)
  45. x_grid = x_grid.reshape((len(x_grid), 1))
  46. plt.plot(x_grid, refressir.predict(x_grid), color = 'blue')
  47. plt.text(8, 1.70, r'Accuracy of the training set')
  48. plt.text(8, 1.50, r'accuracy of the test set')
  49. plt.show()
  50.  
  51. #Древо
  52. clf = tree.DecisionTreeClassifier()
  53. iris = load_iris()
  54. clf = clf.fit(iris.data, iris.target)
  55. tree.export_graphviz(clf)
  56. 'digraph Tree' {"Uniformity of Cell size <= 2,5" -> "Bare Nuclei <= 3,5" [lable = "True"]
  57. "Uniformity of Cell size <= 2,5" -> "Bare Nuclei <= 7,5" [lable = "False"]
  58. "Bare Nuclei <= 3,5" -> "Single Epithelial Cell Size <= 2,5" [lable = "True"]
  59. "Single Epithelial Cell Size <= 2,5" -> "class = benign" [lable = "True"]
  60. "Single Epithelial Cell Size <= 2,5" -> "class = benign" [lable = "False"]
  61. "Bare Nuclei <= 3,5" -> "class = malignant" [lable = "False"]
  62. "Bare Nuclei <= 7,5" -> "Uniformity of Cell size <= 6,5" [lable = "True"]
  63. "Uniformity of Cell size <= 6,5" -> "class = malignant" [lable = "True"]
  64. "Uniformity of Cell size <= 6,5" -> "class = malignant" [lable = "False"]
  65. "Bare Nuclei <= 7,5" -> "Bland Chomathin <= 3,5" [lable = "False"]
  66. "Bland Chomathin <= 3,5" -> "class = malignant" [lable = "True"]
  67. "Bland Chomathin <= 3,5" -> "class = malignant" [lable = "False"]
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement