Search code examples
pythonmachine-learningscikit-learnregressiondecision-tree

How to know the size (Number of nodes) of the tree built using Scikit-learn?


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?


Solution

  • 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.