【问题标题】:increase the size of nodes in decision tree增加决策树中节点的大小
【发布时间】:2021-12-04 19:45:59
【问题描述】:

我正在使用决策树分类器并想使用 matplotlib 绘制树

我正在使用这个,但节点很小且不清楚:

from sklearn import tree
import matplotlib.pyplot as plt

plt.figure(figsize=(15,15))
tree.plot_tree(model_dt_smote,filled=True)

【问题讨论】:

    标签: python matplotlib scikit-learn decision-tree


    【解决方案1】:

    您可以将axe 传递给tree.plot_treefigsize 并设置更大的fontsize,如下所示:

    (我无法运行您的代码,然后我发送一个示例)

    from sklearn.datasets import load_iris
    import matplotlib.pyplot as plt
    from sklearn import tree
    
    clf = tree.DecisionTreeClassifier(random_state=0)
    iris = load_iris()
    clf = clf.fit(iris.data, iris.target)
    
    fig, axe = plt.subplots(figsize=(20,10))
    tree.plot_tree(clf, ax = axe, fontsize=15)
    

    输出:

    【讨论】:

    • 感谢您的回复,但我仍然得到小节点
    • @NitishSantpur 你写这个吗:fig, axe = plt.subplots(figsize=(20,10)); tree.plot_tree(clf, ax = axe, fontsize=15) 你可以改变 figsize 和 fontsize
    • 非常感谢你让我的工作变得简单了只是一个小小的疑问我没有得到特征名称 model_dt_smote=DecisionTreeClassifier(criterion='gini',random_state=100,max_depth=6,min_samples_leaf= 8) tree.plot_tree(model_dt_smote,filled = True,fontsize=10) 你能帮我解决这个问题吗?我得到了类似于上面给出的树 x[35] 等
    • @NitishSantpur 欢迎来到 SO;请看What should I do when someone answers my question?
    猜你喜欢
    • 2015-01-31
    • 2019-02-08
    • 2017-03-26
    • 2016-06-17
    • 2017-01-21
    • 2021-06-17
    • 2013-06-03
    • 2019-01-28
    • 2018-07-31
    相关资源
    最近更新 更多