Beispiel #1
0
def knn(name, **kwargs):
    '''
    Return a pyll graph with hyperparamters that will construct
    a sklearn.neighbors.KNeighborsClassifier model.
    
    See help(hpsklearn.components._knn_hp_space) for info on available KNN 
    arguments.    
    '''
    def _name(msg):
        return '%s.%s_%s' % (name, 'knc', msg)

    hp_space = _knn_hp_space(_name, **kwargs)
    return scope.sklearn_KNeighborsClassifier(**hp_space)
Beispiel #2
0
def knn(name, **kwargs):
    '''
    Return a pyll graph with hyperparamters that will construct
    a sklearn.neighbors.KNeighborsClassifier model.
    
    See help(hpsklearn.components._knn_hp_space) for info on available KNN 
    arguments.    
    '''
    def _name(msg):
        return '%s.%s_%s' % (name, 'knc', msg)

    hp_space = _knn_hp_space(_name, **kwargs)
    return scope.sklearn_KNeighborsClassifier(**hp_space)
Beispiel #3
0
def knn(name,
        sparse_data=False,
        n_neighbors=None,
        weights=None,
        leaf_size=None,
        metric=None,
        p=None,
        **kwargs):
    def _name(msg):
        return '%s.%s_%s' % (name, 'knn', msg)

    if sparse_data:
        metric_args = {'metric': 'euclidean'}
    else:
        metric_args = hp.pchoice(_name('metric'), [
            (0.65, {
                'metric': 'euclidean'
            }),
            (0.10, {
                'metric': 'manhattan'
            }),
            (0.10, {
                'metric': 'chebyshev'
            }),
            (0.10, {
                'metric': 'minkowski',
                'p': scope.int(hp.quniform(_name('minkowski_p'), 1, 5, 1))
            }),
            (0.05, {
                'metric': 'wminkowski',
                'p': scope.int(hp.quniform(_name('wminkowski_p'), 1, 5, 1)),
                'w': hp.uniform(_name('wminkowski_w'), 0, 100)
            }),
        ])

    rval = scope.sklearn_KNeighborsClassifier(
        n_neighbors=scope.int(hp.quniform(_name('n_neighbors'), 0.5, 50, 1))
        if n_neighbors is None else n_neighbors,
        weights=hp.choice(_name('weights'), ['uniform', 'distance'])
        if weights is None else weights,
        leaf_size=scope.int(hp.quniform(_name('leaf_size'), 0.51, 100, 1))
        if leaf_size is None else leaf_size,
        starstar_kwargs=metric_args)
    return rval
Beispiel #4
0
def knn(name,
        sparse_data=False,
        n_neighbors=None,
        weights=None,
        leaf_size=None,
        metric=None,
        p=None,
        **kwargs):

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

    if sparse_data:
      metric_args = { 'metric':'euclidean' }
    else:
      metric_args = hp.pchoice(_name('metric'), [
        (0.65, { 'metric':'euclidean' }),
        (0.10, { 'metric':'manhattan' }),
        (0.10, { 'metric':'chebyshev' }),
        (0.10, { 'metric':'minkowski',
          'p':scope.int(hp.quniform(_name('minkowski_p'), 1, 5, 1))}),
        (0.05, { 'metric':'wminkowski',
          'p':scope.int(hp.quniform(_name('wminkowski_p'), 1, 5, 1)),
          'w':hp.uniform( _name('wminkowski_w'), 0, 100 ) }),
      ] )

    rval = scope.sklearn_KNeighborsClassifier(
        n_neighbors=scope.int(hp.quniform(
            _name('n_neighbors'),
            0.5, 50, 1)) if n_neighbors is None else n_neighbors,
        weights=hp.choice(
            _name('weights'),
            ['uniform', 'distance']) if weights is None else weights,
        leaf_size=scope.int(hp.quniform(
            _name('leaf_size'),
            0.51, 100, 1)) if leaf_size is None else leaf_size,
        starstar_kwargs=metric_args
        )
    return rval
def knn(name,
        n_neighbors=None,
        weights=None,
        algorithm=None,
        leaf_size=None,
        metric=None,
        p=None,
        **kwargs):

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

    """
    metric_arg = hp.choice( _name('metric'), [
      ('euclidean', None, None, None ),
      ('manhattan', None, None, None ),
      ('chebyshev', None, None, None ),
      ('minkowski', hp.quniform(_name('minkowski_p'), 1, 5, 1 ), None, None),
      ('wminkowski', hp.quniform(_name('wminkowski_p'), 1, 5, 1 ),
                      hp.uniform(_name('wminkowski_w'), 0, 100 ), None ),
      ('seuclidean', None, None, hp.uniform(_name('seuclidean_V'), 0, 100)),
      ('mahalanobis', None, None, hp.uniform(_name('mahalanobis_V'), 0, 100)),
    ])
    """
    """
    metric_args = hp.choice(_name('metric'), [
      { 'metric':'euclidean' },
      { 'metric':'manhattan' },
      { 'metric':'chebyshev' },
      { 'metric':'minkowski',
        'p':scope.int(hp.quniform(_name('minkowski_p'), 1, 5, 1))},
      { 'metric':'wminkowski',
        'p':scope.int(hp.quniform(_name('wminkowski_p'), 1, 5, 1)),
        'w':hp.uniform( _name('wminkowski_w'), 0, 100 ) },
      { 'metric':'seuclidean',
        'V':hp.uniform( _name('seuclidean_V'), 0, 100 ) },
      { 'metric':'mahalanobis',
        'V':hp.uniform( _name('mahalanobis_V'), 0, 100 ) },
    ] )
    """

    rval = scope.sklearn_KNeighborsClassifier(
        n_neighbors=scope.int(hp.quniform(
            _name('n_neighbors'),
            0.5, 50, 1)) if n_neighbors is None else n_neighbors,
        weights=hp.choice(
            _name('weights'),
            ['uniform', 'distance']) if weights is None else weights,
        algorithm=hp.choice(
            _name('algorithm'),
            ['ball_tree', 'kd_tree',
             'brute', 'auto']) if algorithm is None else algorithm,
        leaf_size=scope.int(hp.quniform(
            _name('leaf_size'),
            0.51, 100, 1)) if leaf_size is None else leaf_size,
        #TODO: more metrics available
        ###metric_args,
        ##metric=metric_arg[0] if metric is None else metric,
        ##p=metric_arg[1],
        ##w=metric_arg[2],
        ##V=metric_arg[3],
        #metric=hp.choice(
        #    _name('metric'),
        #    [ 'euclidean', 'manhattan', 'chebyshev',
        #      'minkowski' ] ) if metric is None else metric,
        #p=hp.quniform(
        #    _name('p'),
        #    1, 5, 1 ) if p is None else p,
        )
    return rval