Reputation: 354
decReg = DecisionTreeRegressor()
clf = decReg.fit(X, Y)
Intuitively anyone would expect either decReg or calf should have a function which will return the number of nodes in the tree grown. But, I am unable to see any such function. Is there anything else to know the tree size?
Upvotes: 2
Views: 4946
Reputation: 67
# Instantiate a decision tree
clf = tree.DecisionTreeClassifier()
# Fit the decision tree
...
# Print node count
print(clf.tree_.node_count)
Upvotes: 5
Reputation: 6069
According to the documentation, there's tree_
attribute, you can traverse that tree to find any properties of interest. In particular, children_right
and children_left
properties seem to be useful.
Upvotes: 2