ilt*_*p38 20 python decision-tree depth random-forest scikit-learn
我正在使用scikit-learn来创建一个随机森林.但是,我想找到每棵树的各个深度.这似乎是一个简单的属性,但根据文档,(http://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html),无法访问它.
如果这不可能,有没有办法从决策树模型访问树深度?
任何帮助,将不胜感激.谢谢.
jme*_*jme 29
每个实例RandomForestClassifier都有一个estimators_属性,它是一个DecisionTreeClassifier实例列表.文档显示了一个DecisionTreeClassifier具有tree_属性的实例,该属性是(未记录的,我相信)Tree类的实例.在解释一些探索表明,每个Tree实例都有max_depth它的参数似乎是你在找什么-再次,这是无证.
无论如何,如果forest是你的实例RandomForestClassifier,那么:
>>> [estimator.tree_.max_depth for estimator in forest.estimators_]
[9, 10, 9, 11, 9, 9, 11, 7, 13, 10]
Run Code Online (Sandbox Code Playgroud)
应该做的伎俩.
| 归档时间: |
|
| 查看次数: |
8888 次 |
| 最近记录: |