コード例 #1
0
ファイル: components.py プロジェクト: aruneral01/autokit
def random_forest_regressor(name,
                  n_estimators=None,
                  criterion=None,
                  max_features=None,
                  max_depth=None,
                  min_samples_split=None,
                  min_samples_leaf=None,
                  bootstrap=None,
                  oob_score=None,
                  n_jobs=1,
                  random_state=None,
                  verbose=False):

    def _name(msg):
        return '%s.%s_%s' % (name, 'random_forest', msg)

    """
    Out of bag estimation only available if bootstrap=True
    """

    bootstrap_oob = hp.choice(_name('bootstrap_oob'),
                              [(True, True),
                               (True, False),
                               (False, False)])

    rval = scope.sklearn_RandomForestRegressor(
        n_estimators=scope.int(hp.quniform(
            _name('n_estimators'),
            1, 50, 1)) if n_estimators is None else n_estimators,
        criterion=hp.choice(
            _name('criterion'),
            ['mse']) if criterion is None else criterion,
        max_features=hp.choice(
            _name('max_features'),
            ['auto', 'sqrt', 'log2',
             None]) if max_features is None else max_features,
        max_depth=max_depth,
        min_samples_split=hp.quniform(
            _name('min_samples_split'),
            1, 10, 1) if min_samples_split is None else min_samples_split,
        min_samples_leaf=hp.quniform(
            _name('min_samples_leaf'),
            1, 5, 1) if min_samples_leaf is None else min_samples_leaf,
        bootstrap=bootstrap_oob[0] if bootstrap is None else bootstrap,
        oob_score=bootstrap_oob[1] if oob_score is None else oob_score,
        n_jobs=n_jobs,
        random_state=_random_state(_name('rstate'), random_state),
        verbose=verbose,
        )
    return rval
コード例 #2
0
def random_forest_regression(name, criterion='mse', **kwargs):
    '''
    Return a pyll graph with hyperparamters that will construct
    a sklearn.ensemble.RandomForestRegressor model.

    Args:
        criterion([str]): 'mse' is the only choice.
    
    See help(hpsklearn.components._trees_hp_space) for info on additional 
    available random forest/extra trees arguments.    
    '''
    def _name(msg):
        return '%s.%s_%s' % (name, 'rfr', msg)

    hp_space = _trees_hp_space(_name, **kwargs)
    hp_space['criterion'] = criterion
    return scope.sklearn_RandomForestRegressor(**hp_space)
コード例 #3
0
ファイル: components.py プロジェクト: lishen/hyperopt-sklearn
def random_forest_regression(name, criterion='mse', **kwargs):
    '''
    Return a pyll graph with hyperparamters that will construct
    a sklearn.ensemble.RandomForestRegressor model.

    Args:
        criterion([str]): 'mse' is the only choice.
    
    See help(hpsklearn.components._trees_hp_space) for info on additional 
    available random forest/extra trees arguments.    
    '''
    def _name(msg):
        return '%s.%s_%s' % (name, 'rfr', msg)

    hp_space = _trees_hp_space(_name, **kwargs)
    hp_space['criterion'] = criterion
    return scope.sklearn_RandomForestRegressor(**hp_space)
コード例 #4
0
def random_forest_regression(name,
                             n_estimators=None,
                             criterion=None,
                             max_features=None,
                             max_depth=None,
                             min_samples_split=None,
                             min_samples_leaf=None,
                             bootstrap=None,
                             oob_score=None,
                             n_jobs=1,
                             random_state=None,
                             verbose=False):
    def _name(msg):
        return '%s.%s_%s' % (name, 'random_forest_regression', msg)

    """
    Out of bag estimation only available if bootstrap=True
    """

    bootstrap_oob = hp.choice(_name('bootstrap_oob'), [(True, True),
                                                       (True, False),
                                                       (False, False)])

    rval = scope.sklearn_RandomForestRegressor(
        n_estimators=scope.int(hp.quniform(_name('n_estimators'), 1, 50, 1))
        if n_estimators is None else n_estimators,
        criterion="mse" if criterion is None else criterion,
        max_features=hp.choice(_name('max_features'), ['sqrt', 'log2', None])
        if max_features is None else max_features,
        max_depth=max_depth,
        min_samples_split=hp.quniform(_name('min_samples_split'), 1, 10, 1)
        if min_samples_split is None else min_samples_split,
        min_samples_leaf=hp.quniform(_name('min_samples_leaf'), 1, 5, 1)
        if min_samples_leaf is None else min_samples_leaf,
        bootstrap=bootstrap_oob[0] if bootstrap is None else bootstrap,
        oob_score=bootstrap_oob[1] if oob_score is None else oob_score,
        n_jobs=n_jobs,
        random_state=_random_state(_name('rstate'), random_state),
        verbose=verbose,
    )
    return rval