帮我写一段决策树可视化的代码
时间: 2023-03-12 17:11:09 浏览: 104
决策树代码
import matplotlib.pyplot as plt
from sklearn.tree import DecisionTreeClassifier, plot_tree # 定义预测属性和类标签
X = [[0, 0], [1, 1]]
y = [0, 1] # 创建决策树实例
decision_tree_classifier = DecisionTreeClassifier() # 训练模型
model = decision_tree_classifier.fit(X, y) # 可视化
plt.figure(figsize=(10, 8))
plot_tree(model, filled=True, rounded=True, class_names=["0","1"], feature_names=["X1", "X2"])
plt.show()
阅读全文