2016-03-06 45 views

回答

0

要回答我的問題(從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