0
$\begingroup$

I am trying to interpret my decision tree here which was resulted as a part of pre-pruning- enter image description here

I am trying to understand why the values in my nodes are in decimal places. Ideally, they should represent the #observations that belong to a particular class in my binary classifier, they should have been absolute numbers they are not percentages as well since they don't add up to 100.

this is the code I used to plot this tree-

plt.figure(figsize=(15, 10))

out = tree.plot_tree(
    best_model2,
    feature_names=feature_names,
    filled=True,
    fontsize=9,
    node_ids=False,
    class_names=None,
)
for o in out:
    arrow = o.arrow_patch
    if arrow is not None:
        arrow.set_edgecolor("black")
        arrow.set_linewidth(1)
plt.show()

This tree was a post pruned tree with code as -

best_model2 = DecisionTreeClassifier(
    ccp_alpha=0.002, class_weight={0: 0.15, 1: 0.85}, random_state=1
)
best_model2.fit(X_train, y_train)
$\endgroup$
3
  • 3
    $\begingroup$ These values represent the weighted observations for each class, i.e. number of observations per class multiplied by the respective class weight. Since your class weights aren't integers, the resulting values are the way they are. If you want to get class counts, you can simply divide your values by class weights. $\endgroup$
    – Vlad_Z
    Jan 9 at 20:41
  • $\begingroup$ @Vlad_Z, that should be an answer $\endgroup$
    – Ben Reiniger
    Jan 9 at 21:27
  • $\begingroup$ Thanks @vlad_z, please put that as an answer so i can mark it as an answer $\endgroup$
    – ricardo
    Jan 10 at 3:39

1 Answer 1

0
$\begingroup$

This answer was submitted by the user @Vlad_Z

These values represent the weighted observations for each class, i.e. number of observations per class multiplied by the respective class weight. Since your class weights aren't integers, the resulting values are the way they are. If you want to get class counts, you can simply divide your values by class weights.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.