I m building a multiclass decision tree classifier and trying to print decision tree output in textual form. when my dependent variable is 1 this sklearn's export_text lib is giving correct results but it's not the case when we increase no of variables.
Decision Tree Code :
from sklearn.tree import DecisionTreeClassifier
from sklearn import tree
features=['SubChannel']
classess=['spends_bkt','clicks_bkt']
x=data4[features]
y=data4[classes]
dt = DecisionTreeClassifier()
model = dt.fit(x,y)
Export Tree Code :
from sklearn.tree.export import export_text
tree_rules = export_text(dt, feature_names=list(x),max_depth=10, spacing=5, decimals=0, show_weights=True)
print(tree_rules)
Output( When 1 dependent variable):
|----- SubChannel <= 0
| |----- weights: [17, 2, 8, 13, 18, 19] class: 5
|----- SubChannel > 0
| |----- SubChannel <= 2
| | |----- weights: [5, 23, 24, 2, 0, 0] class: 2
| |----- SubChannel > 2
| | |----- SubChannel <= 2
| | | |----- weights: [12, 14, 6, 12, 18, 28] class: 5
| | |----- SubChannel > 2
| | | |----- weights: [24, 19, 20, 31, 22, 11] class: 3
#Here weights represents no of values present in a particular node
Output (when dependent variables are 2):
|----- SubChannel <= 2
| |----- SubChannel <= 2
| | |----- SubChannel <= 0
| | | |----- weights: [17, 15] class: 0
| | |----- SubChannel > 0
| | | |----- weights: [5, 11] class: 1
| |----- SubChannel > 2
| | |----- weights: [12, 9] class: 0
|----- SubChannel > 2
| |----- weights: [24, 27] class: 1
#Can somebody please tell me how this is calculating class and weights