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)
您只需自己从源代码中就可以知道这一点,看看random forest的私有
_set_oob_score
方法是如何工作的。scikit learn中的每个树估计器都有自己的伪随机数生成器种子,它存储在estimator.random_state
字段中。在在拟合过程中,每个估计器学习训练集的子集,用PRNG和种子从
estimator.random_state
生成训练集子集的指标。在这应该是有效的:
相关问题 更多 >
编程相关推荐