最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

scikit learn - sklearn plot_tree function does not show the class when the tree has only one node - Stack Overflow

programmeradmin1浏览0评论

I use the following code to plot a decisions trees:

    plt.figure(figsize=(12, 12))
    plot_tree(estimator, 
            feature_names=feature_names, 
            label= 'all',
            class_names=[f'Class {k}' for k in range(2)], 
            filled=True, 
            rounded=True,
            impurity = True
            )
    plt.title(f"Decision Tree for Effect {effect_name}", fontsize = 40)

    file_name = f"DTs_action_{str(num_action)}/decision_tree_effect_{effect_name}.png"
    plt.savefig(file_name, format="png", dpi=300)  

When the tree has more than one node, I obtain something like:

But when it's a tree with one only node I get:

Why don't I see the class of the node for the case with one node only ?

Thanks

I use the following code to plot a decisions trees:

    plt.figure(figsize=(12, 12))
    plot_tree(estimator, 
            feature_names=feature_names, 
            label= 'all',
            class_names=[f'Class {k}' for k in range(2)], 
            filled=True, 
            rounded=True,
            impurity = True
            )
    plt.title(f"Decision Tree for Effect {effect_name}", fontsize = 40)

    file_name = f"DTs_action_{str(num_action)}/decision_tree_effect_{effect_name}.png"
    plt.savefig(file_name, format="png", dpi=300)  

When the tree has more than one node, I obtain something like:

But when it's a tree with one only node I get:

Why don't I see the class of the node for the case with one node only ?

Thanks

Share Improve this question asked Jan 31 at 17:23 AddonAddon 951 gold badge1 silver badge9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

The answer is that there is only one class in this tree, so no class name is displayed.

You can verify this in the source code: https://github/scikit-learn/scikit-learn/blob/160fe6719a1f44608159b0999dea0e52a83e0963/sklearn/tree/_export.py#L377

发布评论

评论列表(0)

  1. 暂无评论