'Compute out-of-bag score'

def _set_oob_score(self, X, y):

    X = check_array(X, dtype=DTYPE, accept_sparse='csr')
    n_classes_ = self.n_classes_
    n_samples = y.shape[0]
    oob_decision_function = []
    oob_score = 0.0
    predictions = []
    for k in range(self.n_outputs_):
        predictions.append(np.zeros((n_samples, n_classes_[k])))
    for estimator in self.estimators_:
        unsampled_indices = _generate_unsampled_indices(estimator.random_state, n_samples)
        p_estimator = estimator.predict_proba(X[unsampled_indices, :], check_input=False)
        if (self.n_outputs_ == 1):
            p_estimator = [p_estimator]
        for k in range(self.n_outputs_):
            predictions[k][unsampled_indices, :] += p_estimator[k]
    for k in range(self.n_outputs_):
        if (predictions[k].sum(axis=1) == 0).any():
            warn('Some    inputs    do    not    have    OOB    scores.    This    probably    means    too    few    trees    were    used    to    compute    any    reliable    oob    estimates.')
        decision = (predictions[k] / predictions[k].sum(axis=1)[:, np.newaxis])
        oob_decision_function.append(decision)
        oob_score += np.mean((y[:, k] == np.argmax(predictions[k], axis=1)), axis=0)
    if (self.n_outputs_ == 1):
        self.oob_decision_function_ = oob_decision_function[0]
    else:
        self.oob_decision_function_ = oob_decision_function
    self.oob_score_ = (oob_score / self.n_outputs_)
