I have a continuous variable called salary, age etc and output variable as loan_status

Instead of me choosing the cut off points for salary and age bins , I used Decision Tree to compute the bins based on loan_status.

I tried the below

clf = DecisionTreeClassifier(criterion = 'entropy', max_depth = 4)
threshold = clf.tree_.threshold

Got an output like below

> array([ 4.8750e+04,  2.0800e+03,  5.5200e+02,  5.5000e+01,
> -2.0000e+00,
>        -2.0000e+00,  1.9625e+03, -2.0000e+00, -2.0000e+00,  2.3904e+04,
>         4.9075e+03, -2.0000e+00, -2.0000e+00,  4.1600e+04, -2.0000e+00,
>        -2.0000e+00,  4.0000e+06,  1.3765e+06,  1.2765e+06, -2.0000e+00,
>        -2.0000e+00, -2.0000e+00, -2.0000e+00])

a) Can you help me on why do we see -2 items in the threshold output?

b) I don't have any negative values in my dataset for salary. So, don't know what is -2 indicates and how can I avoid this (from generating it)?

c) How to restrict the no of bins to only 3? Currently it produces several thresholds which will increase my bin size to 7 or 8 etc.


1 Answer 1


I believe they are leaf nodes. See here. - "For example, the arrays feature and threshold only apply to split nodes. The values for leaf nodes in these arrays are therefore arbitrary."

Try to use the code in the page to print out the structure of the tree or plot the tree to find the thresholds for split nodes. Then make adjustments to the parameters to adjust your bins sizes.

  • $\begingroup$ Thanks, upvoted. o, we should exclude leaf nodes? And consider positive values for bins? $\endgroup$
    – The Great
    Commented Jan 26, 2022 at 11:28
  • $\begingroup$ If you are looking to understand where the tree split (recursively) on each feature, then ignore the leafs since they are not splitting. However since the documentation says threshold values are arbitrary in leaf nodes, to code this appropriately do not look for positive vs negative since the values may change. Look for split nodes vs leaf nodes and use the value in the split nodes. That follows the example code and the plot_tree $\endgroup$
    – Craig
    Commented Jan 26, 2022 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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