Using sklearn, how do I find depth of a decision tree? Using sklearn, how do I find depth of a decision tree? python python

Using sklearn, how do I find depth of a decision tree?


Access the max_depth for the underlying Tree object:

from sklearn import treeX = [[0, 0], [1, 1]]Y = [0, 1]clf = tree.DecisionTreeClassifier()clf = clf.fit(X, Y)print(clf.tree_.max_depth)>>> 1

You may get more accessible attributes from the underlying tree object using:

help(clf.tree_)

These include max_depth, node_count, and other lower-level parameters.