From 50f652d360676cf588bc823fe7fff2ae809463e8 Mon Sep 17 00:00:00 2001 From: Simon Blanke Date: Sun, 26 May 2024 10:49:05 +0200 Subject: [PATCH] use *args, **kwargs schema to centralize default arguments --- .../machine_learning/_base_machine_learning.py | 4 ++-- .../machine_learning/tabular/_base_tabular.py | 4 ++-- .../tabular/classification/_base_classification.py | 6 ++---- .../test_functions/k_neighbors_classifier.py | 9 ++------- .../tabular/regression/_base_regression.py | 6 ++---- .../test_functions/gradient_boosting_regressor.py | 9 ++------- .../regression/test_functions/k_neighbors_regressor.py | 9 ++------- 7 files changed, 14 insertions(+), 33 deletions(-) diff --git a/src/surfaces/test_functions/machine_learning/_base_machine_learning.py b/src/surfaces/test_functions/machine_learning/_base_machine_learning.py index 87ee173..06060fd 100644 --- a/src/surfaces/test_functions/machine_learning/_base_machine_learning.py +++ b/src/surfaces/test_functions/machine_learning/_base_machine_learning.py @@ -10,8 +10,8 @@ class MachineLearningFunction(BaseTestFunction): - def __init__(self, metric, sleep, evaluate_from_data): - super().__init__(metric, sleep) + def __init__(self, *args, sleep=0, evaluate_from_data=False, **kwargs): + super().__init__(*args, sleep, **kwargs) if evaluate_from_data: self.sdc = SurfacesDataCollector() diff --git a/src/surfaces/test_functions/machine_learning/tabular/_base_tabular.py b/src/surfaces/test_functions/machine_learning/tabular/_base_tabular.py index daf5a5f..52f9832 100644 --- a/src/surfaces/test_functions/machine_learning/tabular/_base_tabular.py +++ b/src/surfaces/test_functions/machine_learning/tabular/_base_tabular.py @@ -7,5 +7,5 @@ class BaseTabular(MachineLearningFunction): - def __init__(self, metric, sleep, evaluate_from_data): - super().__init__(metric, sleep, evaluate_from_data) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) diff --git a/src/surfaces/test_functions/machine_learning/tabular/classification/_base_classification.py b/src/surfaces/test_functions/machine_learning/tabular/classification/_base_classification.py index 31624b1..c79285e 100644 --- a/src/surfaces/test_functions/machine_learning/tabular/classification/_base_classification.py +++ b/src/surfaces/test_functions/machine_learning/tabular/classification/_base_classification.py @@ -7,7 +7,5 @@ class BaseClassification(BaseTabular): - metric = "accuracy" # called 'scoring' in sklearn - - def __init__(self, metric, sleep, evaluate_from_data): - super().__init__(metric, sleep, evaluate_from_data) + def __init__(self, *args, metric="accuracy", **kwargs): + super().__init__(*args, metric, **kwargs) diff --git a/src/surfaces/test_functions/machine_learning/tabular/classification/test_functions/k_neighbors_classifier.py b/src/surfaces/test_functions/machine_learning/tabular/classification/test_functions/k_neighbors_classifier.py index ac44799..6b66626 100644 --- a/src/surfaces/test_functions/machine_learning/tabular/classification/test_functions/k_neighbors_classifier.py +++ b/src/surfaces/test_functions/machine_learning/tabular/classification/test_functions/k_neighbors_classifier.py @@ -20,13 +20,8 @@ class KNeighborsClassifierFunction(BaseClassification): cv_default = [2, 3, 4, 5, 8, 10] dataset_default = [digits_data, wine_data, iris_data] - def __init__( - self, - metric=None, - sleep=0, - evaluate_from_data=False, - ): - super().__init__(metric, sleep, evaluate_from_data) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) def search_space( self, diff --git a/src/surfaces/test_functions/machine_learning/tabular/regression/_base_regression.py b/src/surfaces/test_functions/machine_learning/tabular/regression/_base_regression.py index 280bf8e..a9cc002 100644 --- a/src/surfaces/test_functions/machine_learning/tabular/regression/_base_regression.py +++ b/src/surfaces/test_functions/machine_learning/tabular/regression/_base_regression.py @@ -7,7 +7,5 @@ class BaseRegression(BaseTabular): - metric = "r2" # called 'scoring' in sklearn - - def __init__(self, metric, sleep, evaluate_from_data): - super().__init__(metric, sleep, evaluate_from_data) + def __init__(self, *args, metric="r2", **kwargs): + super().__init__(*args, metric, **kwargs) diff --git a/src/surfaces/test_functions/machine_learning/tabular/regression/test_functions/gradient_boosting_regressor.py b/src/surfaces/test_functions/machine_learning/tabular/regression/test_functions/gradient_boosting_regressor.py index ba2bba2..fd851b3 100644 --- a/src/surfaces/test_functions/machine_learning/tabular/regression/test_functions/gradient_boosting_regressor.py +++ b/src/surfaces/test_functions/machine_learning/tabular/regression/test_functions/gradient_boosting_regressor.py @@ -25,13 +25,8 @@ class GradientBoostingRegressorFunction(BaseRegression): cv_default = [2, 3, 4, 5, 8, 10] dataset_default = [diabetes_data] - def __init__( - self, - metric=None, - sleep=0, - evaluate_from_data=False, - ): - super().__init__(metric, sleep, evaluate_from_data) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) def search_space( self, diff --git a/src/surfaces/test_functions/machine_learning/tabular/regression/test_functions/k_neighbors_regressor.py b/src/surfaces/test_functions/machine_learning/tabular/regression/test_functions/k_neighbors_regressor.py index 1a824f2..b74c86b 100644 --- a/src/surfaces/test_functions/machine_learning/tabular/regression/test_functions/k_neighbors_regressor.py +++ b/src/surfaces/test_functions/machine_learning/tabular/regression/test_functions/k_neighbors_regressor.py @@ -25,13 +25,8 @@ class KNeighborsRegressorFunction(BaseRegression): cv_default = [2, 3, 4, 5, 8, 10] dataset_default = [diabetes_data] - def __init__( - self, - metric=None, - sleep=0, - evaluate_from_data=False, - ): - super().__init__(metric, sleep, evaluate_from_data) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) def search_space( self,