Sklearn random forest - view subset elements of individual decision trees in the forest

I use scikit-learn RandomForestRegressor and I set an explicit value for max_features. When I do this, I expect that for each tree in the forest there is a random subset of max_features length attributes that is considered when assembling the tree (is this correct or does it perform a subset of functions from the entire set of functions for each node of each tree?). I am trying to figure out which subset of functions was used by each tree.

Here is an example of where I am now:

# initialize random forest with 10 trees of depth 2 (max 3 features), 
# with 10 randomly subset features selected per tree
rf = RandomForestRegressor(n_estimators=10, max_depth=2, max_features=10) 
forest = rf.fit(X,y) # fit the model

# get a list of individual DecisionTreeRegressor objects
trees = forest.estimators_ 

If I wanted to know what functions were used in the first tree, I think I can do the following:

[j for j,v in enumerate(trees[0].feature_importances_) if v > 0]

, . () 3 , 10 . , feature_importances_ , , vs, .

, , DecisionTreeRegressor _tree.

.

UPDATE

, , , node, , splitter.features. , .

+4

Source: https://habr.com/ru/post/1660981/


All Articles