Пример #1
0
 def get_decision_tree(self, nominal_indices, **kwargs):
     param_dist = {
         'Estimator__min_samples_split':
         loguniform_int(base=2, low=2**1, high=2**7),
         'Estimator__min_samples_leaf':
         loguniform_int(base=2, low=2**0, high=2**6)
     }
     decision_tree = self._get_pipeline(nominal_indices,
                                        DecisionTreeClassifier())
     random_search = RandomizedSearchCV(decision_tree, param_dist,
                                        **self.rs_arguments)
     return random_search
Пример #2
0
def get_uniform_paramgrid(hyperparameters, fixed_parameters):
    param_grid = dict()
    for param_name, hyperparameter in hyperparameters.items():
        if fixed_parameters is not None and param_name in fixed_parameters.keys(
        ):
            continue
        if isinstance(hyperparameter, CategoricalHyperparameter):
            all_values = hyperparameter.choices
            if all(item in ['True', 'False'] for item in all_values):
                all_values = [bool(item) for item in all_values]
            param_grid[param_name] = all_values
        elif isinstance(hyperparameter, UniformFloatHyperparameter):
            if hyperparameter.log:
                param_grid[param_name] = loguniform(base=2,
                                                    low=hyperparameter.lower,
                                                    high=hyperparameter.upper)
            else:
                param_grid[param_name] = uniform(loc=hyperparameter.lower,
                                                 scale=hyperparameter.upper -
                                                 hyperparameter.lower)
        elif isinstance(hyperparameter, UniformIntegerHyperparameter):
            if hyperparameter.log:
                param_grid[param_name] = loguniform_int(
                    base=2,
                    low=hyperparameter.lower,
                    high=hyperparameter.upper)
            else:
                param_grid[param_name] = randint(low=hyperparameter.lower,
                                                 high=hyperparameter.upper + 1)
        else:
            raise ValueError()
    return param_grid
Пример #3
0
 def test_serialize_complex_param_grid(self):
     # JvR: this unit test seems to fail..
     # TODO: FIXME
     parameter_grid = {
         'n_estimators': [1, 5, 10, 100],
         'learning_rate': loguniform(base=2, low=0.01, high=0.99),
         'base_estimator__max_depth': loguniform_int(base=2, low=1, high=16)
     }
     serialized = openml.flows.sklearn_to_flow(parameter_grid)
     deserialized = dict(openml.flows.flow_to_sklearn(serialized))
     self.assertDictEqual(parameter_grid, deserialized)
Пример #4
0
 def get_mlp(self, nominal_indices, **kwargs):
     param_dist = {
         'Estimator__hidden_layer_sizes':
         loguniform_int(base=2, low=2**5, high=2**11),
         'Estimator__learning_rate_init':
         loguniform(base=10, low=10**-5, high=10**0),
         'Estimator__alpha':
         loguniform(base=10, low=10**-7, high=10**-4),
         'Estimator__max_iter':
         scipy.stats.randint(2, 1001),
         'Estimator__momentum':
         scipy.stats.uniform(loc=0.1, scale=0.8)
     }
     mlp = self._get_pipeline(
         nominal_indices, MLPClassifier(activation='tanh', solver='adam'))
     random_search = RandomizedSearchCV(mlp, param_dist,
                                        **self.rs_arguments)
     return random_search