woo*_*oot 2 python machine-learning random-forest scikit-learn
我试图访问与RandomForestClassifier中的每棵树相关联的无用示例。我发现了其他信息,例如每个节点的Gini得分和拆分功能,查看那里:https : //github.com/scikit-learn/scikit-learn/blob/master/sklearn/tree/_tree.pyx
有谁知道是否有可能获得与树相关的袋装样本?如果不是,有可能获得“袋装”样本(用于特定树的数据集的子集),然后使用原始数据集计算OOB?
提前致谢
您可以从源代码中自己找出来,看看_set_oob_score随机森林的私有方法是如何工作的。scikit-learn中的每个树估计器都有它自己的伪随机数生成器种子,它存储在estimator.random_state字段内部。
在拟合过程中,每个估计量都在训练集的子集上学习,训练集的子集的索引将使用PRNG和的种子生成estimator.random_state。
这应该工作:
from sklearn.ensemble.forest import _generate_unsampled_indices
# X here - training set of examples
n_samples = X.shape[0]
for tree in rf.estimators_:
# Here at each iteration we obtain out of bag samples for every tree.
unsampled_indices = _generate_unsampled_indices(
tree.random_state, n_samples)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
970 次 |
| 最近记录: |