machine learning - How to find out the size of a sklearn decision tree in python? -
I am adding some specialty with decision trees and in terms of the number of nodes, I want to know the size of the tree. How can I do this in a dragon?
Using stock example from Schenene's website,
x = [[0,0], [0,1]] y = [0,1] sklearn RandomForestClassifier clf = RandomForestClassifer (n_estimators = 10) clf = clf.fit (x, y) from .esemble import
I can do something like clf to individual trees [1], clf [...], but how can I determine the size of each tree in terms of the total node number?
A sklearn.tree._tree.Tree object has a 'node_count' property:
Scalean import from tree X = [[0, 0], [1, 1]] Y = [0, 1] clf = tree.DecisionTreeClassifier () clf = clf.fit (x, y) tree Obz = clf.tree_ print tree obz.node_ count
Comments
Post a Comment