Extracting trees (predictor) from an arbitrary forest classifier

I have a special technical question about sklearn, a random forest classifier.

After setting the data using the ".fit (X, y)" method, is there a way to extract the actual trees from the evaluator object in some common format, so the ".predict (X)" method can be implemented outside of python?

+7
scikit-learn
source share
1 answer

Yes, forest trees are stored in the estimators_ attribute of the estimators_ object.

You can take a look at the export_graphviz implementation to learn how to write your custom exporter:

https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/tree/export.py

Here is an example of using this function:

http://scikit-learn.org/stable/modules/tree.html#classification

+12
source share

All Articles