Advertisement
fevzi02

Untitled

Dec 26th, 2023
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. from sklearn.datasets import load_iris
  2. from sklearn.model_selection import train_test_split
  3. from sklearn.tree import DecisionTreeClassifier
  4. from sklearn import tree
  5. import matplotlib.pyplot as plt
  6.  
  7. # Загрузите набор данных iris или ваш конкретный набор данных
  8. data = load_iris()
  9. X = data.data
  10. y = data.target
  11.  
  12. # Разделите набор данных на обучающий и тестовый наборы
  13. X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
  14.  
  15. # Инициализируйте DecisionTreeClassifier
  16. clf = DecisionTreeClassifier(random_state=42)
  17.  
  18. # Обучите модель на обучающих данных
  19. clf.fit(X_train, y_train)
  20.  
  21. # Визуализируйте решающее дерево
  22. plt.figure(figsize=(12,8))
  23. tree.plot_tree(clf, filled=True, feature_names=data.feature_names, class_names=data.target_names)
  24. plt.show()
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement