1
是否有某種方法可以識別用於構造RandomForest{Classifier, Regressor}
對象中每棵樹的樣本?RandomForest *對象的「In-bag」
我找「keep.inbag」在該R實現等價的:http://math.furman.edu/~dcs/courses/math47/R/library/randomForest/html/randomForest.html
是否有某種方法可以識別用於構造RandomForest{Classifier, Regressor}
對象中每棵樹的樣本?RandomForest *對象的「In-bag」
我找「keep.inbag」在該R實現等價的:http://math.furman.edu/~dcs/courses/math47/R/library/randomForest/html/randomForest.html
要回答我的問題(從scikit學習郵件列表上@amueller幫助 - 謝謝!),在這裏是計算包內矩陣的函數:
from sklearn.ensemble.forest import _generate_sample_indices
def calc_inbag(n_samples, forest):
n_trees = forest.n_estimators
inbag = np.zeros((n_samples, n_trees))
for t_idx in range(n_trees):
sample_idx = _generate_sample_indices(forest.estimators_[t_idx].random_state,
n_samples)
inbag[:, t_idx] = np.bincount(sample_idx, minlength=n_samples)
return inbag