user15910272
user15910272

Reputation:

How to find the max depth in a random forest classifier?

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.

Upvotes: 2

Views: 972

Answers (1)

dx2-66
dx2-66

Reputation: 2851

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)

Upvotes: 1

Related Questions