madlib-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iyerr3 <...@git.apache.org>
Subject [GitHub] incubator-madlib pull request: SVM: Add cross validation support a...
Date Tue, 24 Nov 2015 22:48:28 GMT
Github user iyerr3 commented on a diff in the pull request:

    https://github.com/apache/incubator-madlib/pull/4#discussion_r45806649
  
    --- Diff: src/ports/postgres/modules/svm/svm.py_in ---
    @@ -440,55 +595,68 @@ def _process_epsilon(is_svc, args):
     def _extract_params(schema_madlib, params, module='SVM'):
         # NOTICE: the type of values in params_default should be consistent with
         # the types specified in params_types
    -    params_default = {'init_stepsize': 0.01,
    -                      'decay_factor': 0.9,
    -                      'max_iter': 100,
    -                      'tolerance': 1e-10,
    -                      'lambda': 1.0,
    -                      'norm': 'L2',
    -                      'n_folds': 0,
    -                      'epsilon': 0.01,
    -                      'eps_table': ''}
    -
    -    params_types = {'init_stepsize': float,
    -                    'decay_factor': float,
    -                    'max_iter': int,
    -                    'tolerance': float,
    -                    'lambda': list,
    -                    'norm': str,
    -                    'n_folds': int,
    -                    'epsilon': float,
    -                    'eps_table': str}
    +    params_default = {
    +                        'init_stepsize': [0.01],
    +                        'decay_factor': [0.9],
    +                        'max_iter': [100],
    +                        'tolerance': 1e-10,
    +                        'lambda': [0.01],
    +                        'norm': 'L2',
    +                        'n_folds': 0,
    +                        'validation_result': '',
    +                        'epsilon': [0.01],
    +                        'eps_table': ''}
    +
    +    params_types = {
    +                        'init_stepsize': list,
    +                        'decay_factor': list,
    +                        'max_iter': list,
    +                        'tolerance': float,
    +                        'lambda': list,
    +                        'norm': str,
    +                        'n_folds': int,
    +                        'validation_result': str,
    +                        'epsilon': list,
    +                        'eps_table': str}
     
         params_vals = extract_keyvalue_params(params,
                                               params_types,
                                               params_default)
    -
         if params_vals['n_folds'] < 0:
    -        plpy.error("SVM error: n_folds must be non-negative")
    -    # FIXME
    -    _assert(params_vals['n_folds'] <= 1,
    -            "SVM error: cross-validation has not been implemented")
    +        plpy.error("{0} error: n_folds must be non-negative!".format(module))
     
         # validate lambda
    -    if hasattr(params_vals['lambda'], '__len__'):
    -        # this check should be removed after cross validation is added
    -        if len(params_vals['lambda']) != 1:
    -            plpy.error("{0} error: lambda must be a scalar or of length 1 when n_folds
is 0 or 1".format(module))
    -        params_vals['lambda'] = params_vals['lambda'][0]
    -    _assert(params_vals['lambda'] >= 0,
    -            "SVM error: lambda must be non-negative!")
    +    params_vals['lambda'] = map(float, params_vals['lambda'])
    +    if [lmd for lmd in params_vals['lambda'] if lmd < 0]:
    --- End diff --
    
    I would prefer to read this as `any(l < 0 for l in params_val['lambda']`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message