

def sub_ensemble(ensemble, n_estimators, seed=None):
    'Build a new ensemble with a random subset of the sub-estimators\n\n        >>> from sklearn.datasets import load_iris\n        >>> from sklearn.ensemble import ExtraTreesClassifier\n        >>> iris = load_iris()\n        >>> X, y = iris.data, iris.target\n\n        >>> big = ExtraTreesClassifier(n_estimators=10).fit(X, y)\n        >>> small = sub_ensemble(big, 3)\n        >>> len(small.estimators_)\n        3\n        >>> small.n_estimators\n        3\n        >>> small.score(X, y)\n        1.0\n\n    '
    rng = Random(seed)
    final_ensemble = copy(ensemble)
    if (n_estimators > len(ensemble.estimators_)):
        raise ValueError(('Cannot sample %d estimators from ensemble of %d' % (n_estimators, len(ensemble.estimators_))))
    final_ensemble.estimators_ = rng.sample(ensemble.estimators_, n_estimators)
    final_ensemble.n_estimators = len(ensemble.estimators_)
    return final_ensemble

dataset/ETHPy150Open pydata/pyrallel/pyrallel/ensemble.py sub_ensemble/VarMisuse@87/327 `final_ensemble`->`ensemble`