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 badges1 Answer
Reset to default 0The 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