小编Kar*_*s32的帖子

如何使用sklearnplot_tree更改决策树图的颜色?

如何使用 sklearn.tree.plot_tree 更改决策树图中的颜色而不使用 graphviz,如本问题所示:更改使用导出 graphviz 创建的决策树图的颜色

plt.figure(figsize=[21, 6])
ax1 = plt.subplot(121)
ax2 = plt.subplot(122)

ax1.plot(X[:, 0][y == 0], X[:, 1][y == 0], "bo")
ax1.plot(X[:, 0][y == 1], X[:, 1][y == 1], "g^")
ax1.contourf(xx, yy, pred.reshape(xx.shape), cmap=matplotlib.colors.ListedColormap(['b', 'g']), alpha=0.25)
ax1.set_title(title)

plot_tree(tree_clf, feature_names=["X", "y"], class_names=["blue", "green"], filled=True, rounded=True)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

python matplotlib scikit-learn

8
推荐指数
1
解决办法
5373
查看次数

标签 统计

matplotlib ×1

python ×1

scikit-learn ×1