Beispiel #1
0
class SvcConfiguration(ClassifierConfiguration):
    def __init__(self, num_folds, sample_weight, families_supervision,
                 test_conf):
        ClassifierConfiguration.__init__(self,
                                         num_folds,
                                         sample_weight,
                                         families_supervision,
                                         test_conf=test_conf)
        self.model_class = Svc
        self.c = LearningParameter(list(10.**np.arange(-2, 2)))

    def getModelClassName(self):
        return 'Svc'

    def setC(self, c_values):
        self.c = LearningParameter(c_values)

    def getParamGrid(self):
        param_grid = {'model__C': self.c.values}
        return param_grid

    def setBestValues(self, grid_search):
        self.c.setBestValue(grid_search.best_params_['model__C'])

    def getBestValues(self):
        best_values = {'model__C': self.c.best_value}
        return best_values

    @staticmethod
    def fromJson(obj, exp):
        test_conf = TestConfiguration.fromJson(obj['test_conf'], exp)
        conf = SvcConfiguration(obj['num_folds'], obj['sample_weight'],
                                obj['families_supervision'], test_conf)
        conf.c = LearningParameter.fromJson(obj['c'])
        return conf

    def toJson(self):
        conf = ClassifierConfiguration.toJson(self)
        conf['__type__'] = 'SvcConfiguration'
        conf['c'] = self.c.toJson()
        return conf

    def probabilistModel(self):
        return False

    def semiSupervisedModel(self):
        return False

    def featureImportance(self):
        return None

    @staticmethod
    def generateParser(parser):
        classifier_group = ClassifierConfiguration.generateParser(parser)

    @staticmethod
    def generateParamsFromArgs(args, experiment):
        params = ClassifierConfiguration.generateParamsFromArgs(
            args, experiment)
        return params
Beispiel #2
0
 def __init__(self, num_folds, sample_weight, families_supervision,
              test_conf):
     ClassifierConfiguration.__init__(self,
                                      num_folds,
                                      sample_weight,
                                      families_supervision,
                                      test_conf=test_conf)
     self.model_class = Svc
     self.c = LearningParameter(list(10.**np.arange(-2, 2)))
Beispiel #3
0
 def fromJson(obj, exp):
     test_conf = TestConfiguration.fromJson(obj['test_conf'], exp)
     conf = LogisticRegressionConfiguration(obj['num_folds'], obj['sample_weight'],
                                            obj['families_supervision'], obj['optim_algo'],
                                            test_conf)
     conf.c          = LearningParameter.fromJson(obj['c'])
     conf.penalty    = LearningParameter.fromJson(obj['penalty'])
     conf.optim_algo = obj['optim_algo']
     return conf
    def __init__(self, num_folds, sample_weight, families_supervision,
                 test_conf):
        ClassifierConfiguration.__init__(self,
                                         num_folds,
                                         sample_weight,
                                         families_supervision,
                                         test_conf=test_conf)
        self.model_class = LogisticRegression

        #self.optim_algo = 'sag'
        #self.c = LearningParameter(list(10. ** np.arange(-2, 2)))
        #self.penalty = LearningParameter(['l2'])

        self.optim_algo = 'liblinear'
        self.c = LearningParameter(list(10.**np.arange(-2, 2)))
        self.penalty = LearningParameter(['l1', 'l2'])
Beispiel #5
0
 def fromJson(obj, exp):
     conf = SvcConfiguration(obj['num_folds'], obj['sample_weight'],
                             obj['families_supervision'])
     ClassifierConfiguration.setTestConfiguration(conf, obj, exp)
     conf.c = LearningParameter.fromJson(obj['c'])
     return conf
Beispiel #6
0
 def setC(self, c_values):
     self.c = LearningParameter(c_values)
Beispiel #7
0
 def setPenalty(self, penalty_values):
     self.penalty = LearningParameter(penalty_values)
Beispiel #8
0
class LogisticRegressionConfiguration(ClassifierConfiguration):
    def __init__(self, num_folds, sample_weight, families_supervision,
                 optim_algo, test_conf):
        ClassifierConfiguration.__init__(self,
                                         num_folds,
                                         sample_weight,
                                         families_supervision,
                                         test_conf=test_conf)
        self.model_class = LogisticRegression
        if optim_algo is not None:
            self.optim_algo = optim_algo
        else:
            self.optim_algo = 'liblinear'
        self.c = LearningParameter(list(10.**np.arange(-2, 2)))
        if self.optim_algo == 'sag':
            self.penalty = LearningParameter(['l2'])
        elif self.optim_algo == 'liblinear':
            self.penalty = LearningParameter(['l1', 'l2'])

    def getModelClassName(self):
        return 'LogisticRegression'

    def generateSuffix(self):
        suffix = ClassifierConfiguration.generateSuffix(self)
        suffix += '__' + self.optim_algo
        return suffix

    def setC(self, c_values):
        self.c = LearningParameter(c_values)

    def setPenalty(self, penalty_values):
        self.penalty = LearningParameter(penalty_values)

    def setOptimAlgo(self, optim_algo):
        self.optim_algo = optim_algo

    def getParamGrid(self):
        param_grid = {
            'model__C': self.c.values,
            'model__penalty': self.penalty.values
        }
        return param_grid

    def setBestValues(self, grid_search):
        self.c.setBestValue(grid_search.best_params_['model__C'])
        self.penalty.setBestValue(grid_search.best_params_['model__penalty'])

    def getBestValues(self):
        best_values = {
            'model__C': self.c.best_value,
            'model__penalty': self.penalty.best_value
        }
        return best_values

    @staticmethod
    def fromJson(obj, exp):
        test_conf = TestConfiguration.fromJson(obj['test_conf'], exp)
        conf = LogisticRegressionConfiguration(obj['num_folds'],
                                               obj['sample_weight'],
                                               obj['families_supervision'],
                                               obj['optim_algo'], test_conf)
        ClassifierConfiguration.setTestConfiguration(conf, obj, exp)
        conf.c = LearningParameter.fromJson(obj['c'])
        conf.penalty = LearningParameter.fromJson(obj['penalty'])
        conf.optim_algo = obj['optim_algo']
        return conf

    def toJson(self):
        conf = ClassifierConfiguration.toJson(self)
        conf['__type__'] = 'LogisticRegressionConfiguration'
        conf['optim_algo'] = self.optim_algo
        conf['c'] = self.c.toJson()
        conf['penalty'] = self.penalty.toJson()
        return conf

    def probabilistModel(self):
        return True

    def semiSupervisedModel(self):
        return False

    def featureCoefficients(self):
        return not (self.families_supervision)

    @staticmethod
    def generateParser(parser):
        ClassifierConfiguration.generateParser(parser)
        parser.add_argument('--optim-algo',
                            choices=['sag', 'liblinear'],
                            default='liblinear',
                            help='sag is recommended for large datasets.')

    @staticmethod
    def generateParamsFromArgs(args, experiment):
        params = ClassifierConfiguration.generateParamsFromArgs(
            args, experiment)
        params['optim_algo'] = args.optim_algo
        return params
Beispiel #9
0
 def fromJson(obj, exp):
     test_conf = TestConfiguration.fromJson(obj['test_conf'], exp)
     conf = SvcConfiguration(obj['num_folds'], obj['sample_weight'],
                             obj['families_supervision'], test_conf)
     conf.c = LearningParameter.fromJson(obj['c'])
     return conf
class LogisticRegressionConfiguration(ClassifierConfiguration):
    def __init__(self, num_folds, sample_weight, families_supervision,
                 test_conf):
        ClassifierConfiguration.__init__(self,
                                         num_folds,
                                         sample_weight,
                                         families_supervision,
                                         test_conf=test_conf)
        self.model_class = LogisticRegression

        #self.optim_algo = 'sag'
        #self.c = LearningParameter(list(10. ** np.arange(-2, 2)))
        #self.penalty = LearningParameter(['l2'])

        self.optim_algo = 'liblinear'
        self.c = LearningParameter(list(10.**np.arange(-2, 2)))
        self.penalty = LearningParameter(['l1', 'l2'])

    def getModelClassName(self):
        return 'LogisticRegression'

    def setC(self, c_values):
        self.c = LearningParameter(c_values)

    def setPenalty(self, penalty_values):
        self.penalty = LearningParameter(penalty_values)

    def setOptimAlgo(self, optim_algo):
        self.optim_algo = optim_algo

    def getParamGrid(self):
        param_grid = {
            'model__C': self.c.values,
            'model__penalty': self.penalty.values
        }
        return param_grid

    def setBestValues(self, grid_search):
        self.c.setBestValue(grid_search.best_params_['model__C'])
        self.penalty.setBestValue(grid_search.best_params_['model__penalty'])

    def getBestValues(self):
        best_values = {
            'model__C': self.c.best_value,
            'model__penalty': self.penalty.best_value
        }
        return best_values

    @staticmethod
    def fromJson(obj, exp):
        test_conf = TestConfiguration.fromJson(obj['test_conf'], exp)
        conf = LogisticRegressionConfiguration(obj['num_folds'],
                                               obj['sample_weight'],
                                               obj['families_supervision'],
                                               test_conf)
        ClassifierConfiguration.setTestConfiguration(conf, obj, exp)
        conf.c = LearningParameter.fromJson(obj['c'])
        conf.penalty = LearningParameter.fromJson(obj['penalty'])
        conf.optim_algo = obj['optim_algo']
        return conf

    def toJson(self):
        conf = ClassifierConfiguration.toJson(self)
        conf['__type__'] = 'LogisticRegressionConfiguration'
        conf['optim_algo'] = self.optim_algo
        conf['c'] = self.c.toJson()
        conf['penalty'] = self.penalty.toJson()
        return conf

    def probabilistModel(self):
        return True

    def semiSupervisedModel(self):
        return False

    def featureCoefficients(self):
        return not (self.families_supervision)

    @staticmethod
    def generateParser(parser):
        classifier_group = ClassifierConfiguration.generateParser(parser)

    @staticmethod
    def generateParamsFromArgs(args, experiment):
        params = ClassifierConfiguration.generateParamsFromArgs(
            args, experiment)
        return params