首页 文章

Scikit-learn随机森林袋样品

提问于
浏览
2

我试图在没有运气的情况下访问RandomForestClassifier中与每棵树相关联的袋子样本 . 我找到了其他信息,如基尼评分和每个节点的拆分功能,看那里:https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/tree/_tree.pyx

有谁知道是否有可能从树上取出与样品相关的样品?如果没有,也许可以获得'in bag'样本(用于特定树的数据集的子集),然后使用原始数据集计算OOB?

提前致谢

1 回答

  • 3

    您可以从源代码中自己解决这个问题,看看随机林的私有 _set_oob_score 方法是如何工作的 . scikit-learn中的每个树估算器都将's own seed for pseudo random number generator, it'存储在 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)
    

相关问题