From 0bf4b93cf296ec8057112b0f6f1c35ff17a6a336 Mon Sep 17 00:00:00 2001 From: Simon Blanke Date: Sun, 31 Dec 2023 15:57:30 +0100 Subject: [PATCH] remove input type --- .../base_machine_learning_function.py | 4 ++-- .../tabular_classifiers.py | 5 ++++- .../machine_learning_functions/tabular_regressors.py | 10 ++++++++-- .../_base_objective_function.py | 12 ++++++------ 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/surfaces/machine_learning_functions/base_machine_learning_function.py b/surfaces/machine_learning_functions/base_machine_learning_function.py index fc7092d..3f2cc62 100644 --- a/surfaces/machine_learning_functions/base_machine_learning_function.py +++ b/surfaces/machine_learning_functions/base_machine_learning_function.py @@ -13,8 +13,8 @@ class MachineLearningFunction(BaseTestFunction): - def __init__(self, input_type="dictionary"): - super().__init__(input_type) + def __init__(self): + super().__init__() self.objective_function.__func__.__name__ = self.__name__ diff --git a/surfaces/machine_learning_functions/tabular_classifiers.py b/surfaces/machine_learning_functions/tabular_classifiers.py index 7fc3e64..98cb95b 100644 --- a/surfaces/machine_learning_functions/tabular_classifiers.py +++ b/surfaces/machine_learning_functions/tabular_classifiers.py @@ -13,7 +13,10 @@ class KNeighborsClassifierFunction(MachineLearningFunction): __name__ = "k_neighbors_classifier" def __init__(self, input_type="dictionary", sleep=0): - super().__init__(input_type, sleep) + super().__init__() + + self.input_type = input_type + self.sleep = sleep self.search_space = { "n_neighbors": list(np.arange(3, 150)), diff --git a/surfaces/machine_learning_functions/tabular_regressors.py b/surfaces/machine_learning_functions/tabular_regressors.py index 16a543e..cfac852 100644 --- a/surfaces/machine_learning_functions/tabular_regressors.py +++ b/surfaces/machine_learning_functions/tabular_regressors.py @@ -14,7 +14,10 @@ class KNeighborsRegressorFunction(MachineLearningFunction): __name__ = "k_neighbors_regressor" def __init__(self, input_type="dictionary", sleep=0): - super().__init__(input_type, sleep) + super().__init__() + + self.input_type = input_type + self.sleep = sleep self.search_space = { "n_neighbors": list(np.arange(3, 150)), @@ -37,7 +40,10 @@ class GradientBoostingRegressorFunction(MachineLearningFunction): __name__ = "gradient_boosting_regressor" def __init__(self, input_type="dictionary", sleep=0): - super().__init__(input_type, sleep) + super().__init__() + + self.input_type = input_type + self.sleep = sleep self.search_space = { "n_estimators": list(np.arange(5, 150)), diff --git a/surfaces/mathematical_functions/_base_objective_function.py b/surfaces/mathematical_functions/_base_objective_function.py index 7dae2dc..b885fc1 100644 --- a/surfaces/mathematical_functions/_base_objective_function.py +++ b/surfaces/mathematical_functions/_base_objective_function.py @@ -28,35 +28,35 @@ def __init__(self, metric="score", input_type="dictionary", sleep=0): self.input_type = input_type self.sleep = sleep - def search_space(self, min=-5, max=5, step=0.1, value_typ="array"): + def search_space(self, min=-5, max=5, step=0.1, value_types="array"): search_space_ = {} for dim in range(self.n_dim): dim_str = "x" + str(dim) values = np.arange(min, max, step) - if value_typ == "list": + if value_types == "list": values = list(values) search_space_[dim_str] = values return search_space_ def collect_data(self, if_exists="append"): - self.search_space = self.search_space(value_typ="list") + self.search_space = self.search_space(value_types="list") - para_names = list(self.search_space().keys()) + para_names = list(self.search_space.keys()) search_data_cols = para_names + ["score"] search_data = pd.DataFrame([], columns=search_data_cols) search_data_length = 0 - dim_sizes_list = [len(array) for array in self.search_space().values()] + dim_sizes_list = [len(array) for array in self.search_space.values()] search_space_size = reduce((lambda x, y: x * y), dim_sizes_list) while search_data_length < search_space_size: hyper = Hyperactive(verbosity=["progress_bar"]) hyper.add_search( self.objective_function_dict, - self.search_space(value_typ="list"), + self.search_space, initialize={}, n_iter=search_space_size, optimizer=GridSearchOptimizer(direction="orthogonal"),