3

I've a random forest classifier in Python with default parameters. After the classifier is built is it possible to find the max depth in random forest classifier ?

For decision tree classifier we have tree.max_depth().
Example : this

I know we can set max_depth in Random forest classifier but given a classifier with default values can we get this max_depth ? Please help.

rockstar
  • 67
  • 7

1 Answers1

1

All the trees are accessible via estimators_ attribute, so you should be able to do something like:

max((e.tree_.max_depth for e in rf.estimators_))

(assuming rf is a fitted instance of a RandomForestClassifier)

dx2-66
  • 2,376
  • 2
  • 4
  • 14