-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
complete restructure of ml-test-functions
- Loading branch information
1 parent
f10d867
commit 3f79f6e
Showing
18 changed files
with
243 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,8 @@ | |
# Email: [email protected] | ||
# License: MIT License | ||
|
||
from .mathematical import ( | ||
mathematical_functions, | ||
) | ||
from .mathematical import mathematical_functions | ||
|
||
from .machine_learning import machine_learning_functions | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
7 changes: 0 additions & 7 deletions
7
src/surfaces/test_functions/machine_learning/datasets/__init__.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Author: Simon Blanke | ||
# Email: [email protected] | ||
# License: MIT License | ||
|
||
from .classification import KNeighborsClassifierFunction | ||
from .regression import KNeighborsRegressorFunction, GradientBoostingRegressorFunction | ||
|
||
|
||
__all__ = [ | ||
"KNeighborsClassifierFunction", | ||
"KNeighborsRegressorFunction", | ||
"GradientBoostingRegressorFunction", | ||
] |
11 changes: 11 additions & 0 deletions
11
src/surfaces/test_functions/machine_learning/tabular/_base_tabular.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Author: Simon Blanke | ||
# Email: [email protected] | ||
# License: MIT License | ||
|
||
|
||
from .._base_machine_learning import MachineLearningFunction | ||
|
||
|
||
class BaseTabular(MachineLearningFunction): | ||
def __init__(self, metric, sleep, evaluate_from_data): | ||
super().__init__(metric, sleep, evaluate_from_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Author: Simon Blanke | ||
# Email: [email protected] | ||
# License: MIT License | ||
|
||
from .test_functions import ( | ||
KNeighborsClassifierFunction, | ||
) | ||
|
||
|
||
__all__ = [ | ||
"KNeighborsClassifierFunction", | ||
] |
13 changes: 13 additions & 0 deletions
13
src/surfaces/test_functions/machine_learning/tabular/classification/_base_classification.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Author: Simon Blanke | ||
# Email: [email protected] | ||
# License: MIT License | ||
|
||
|
||
from .._base_tabular import BaseTabular | ||
|
||
|
||
class BaseClassification(BaseTabular): | ||
metric = "accuracy" # called 'scoring' in sklearn | ||
|
||
def __init__(self, metric, sleep, evaluate_from_data): | ||
super().__init__(metric, sleep, evaluate_from_data) |
File renamed without changes.
11 changes: 11 additions & 0 deletions
11
...urfaces/test_functions/machine_learning/tabular/classification/test_functions/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Author: Simon Blanke | ||
# Email: [email protected] | ||
# License: MIT License | ||
|
||
|
||
from .k_neighbors_classifier import KNeighborsClassifierFunction | ||
|
||
|
||
__all__ = [ | ||
"KNeighborsClassifierFunction", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Author: Simon Blanke | ||
# Email: [email protected] | ||
# License: MIT License | ||
|
||
from .test_functions import ( | ||
KNeighborsRegressorFunction, | ||
GradientBoostingRegressorFunction, | ||
) | ||
|
||
|
||
__all__ = [ | ||
"KNeighborsRegressorFunction", | ||
"GradientBoostingRegressorFunction", | ||
] |
13 changes: 13 additions & 0 deletions
13
src/surfaces/test_functions/machine_learning/tabular/regression/_base_regression.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Author: Simon Blanke | ||
# Email: [email protected] | ||
# License: MIT License | ||
|
||
|
||
from .._base_tabular import BaseTabular | ||
|
||
|
||
class BaseRegression(BaseTabular): | ||
metric = "r2" # called 'scoring' in sklearn | ||
|
||
def __init__(self, metric, sleep, evaluate_from_data): | ||
super().__init__(metric, sleep, evaluate_from_data) |
File renamed without changes.
13 changes: 13 additions & 0 deletions
13
src/surfaces/test_functions/machine_learning/tabular/regression/test_functions/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Author: Simon Blanke | ||
# Email: [email protected] | ||
# License: MIT License | ||
|
||
|
||
from .k_neighbors_regressor import KNeighborsRegressorFunction | ||
from .gradient_boosting_regressor import GradientBoostingRegressorFunction | ||
|
||
|
||
__all__ = [ | ||
"KNeighborsRegressorFunction", | ||
"GradientBoostingRegressorFunction", | ||
] |
66 changes: 66 additions & 0 deletions
66
...nctions/machine_learning/tabular/regression/test_functions/gradient_boosting_regressor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Author: Simon Blanke | ||
# Email: [email protected] | ||
# License: MIT License | ||
|
||
|
||
import numpy as np | ||
|
||
from sklearn.ensemble import GradientBoostingRegressor | ||
|
||
from sklearn.model_selection import cross_val_score | ||
from ..datasets import diabetes_data | ||
|
||
from .._base_regression import BaseRegression | ||
|
||
|
||
class GradientBoostingRegressorFunction(BaseRegression): | ||
name = "Gradient Boosting Regressor Function" | ||
_name_ = "gradient_boosting_regressor" | ||
__name__ = "GradientBoostingRegressorFunction" | ||
|
||
para_names = ["n_estimators", "max_depth", "cv", "dataset"] | ||
|
||
n_estimators_default = list(np.arange(3, 150, 5)) | ||
max_depth_default = list(np.arange(2, 25)) | ||
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 search_space( | ||
self, | ||
n_estimators: list = None, | ||
max_depth: list = None, | ||
cv: list = None, | ||
dataset: list = None, | ||
): | ||
search_space: dict = {} | ||
|
||
search_space["n_estimators"] = ( | ||
self.n_estimators_default if n_estimators is None else n_estimators | ||
) | ||
search_space["max_depth"] = ( | ||
self.max_depth_default if max_depth is None else max_depth | ||
) | ||
search_space["cv"] = self.cv_default if cv is None else cv | ||
search_space["dataset"] = self.dataset_default if dataset is None else dataset | ||
|
||
return search_space | ||
|
||
def create_objective_function(self): | ||
def gradient_boosting_regressor(params): | ||
knc = GradientBoostingRegressor( | ||
n_estimators=params["n_estimators"], | ||
max_depth=params["max_depth"], | ||
) | ||
X, y = params["dataset"]() | ||
scores = cross_val_score(knc, X, y, cv=params["cv"], scoring=self.metric) | ||
return scores.mean() | ||
|
||
self.pure_objective_function = gradient_boosting_regressor |
66 changes: 66 additions & 0 deletions
66
...est_functions/machine_learning/tabular/regression/test_functions/k_neighbors_regressor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Author: Simon Blanke | ||
# Email: [email protected] | ||
# License: MIT License | ||
|
||
|
||
import numpy as np | ||
|
||
from sklearn.neighbors import KNeighborsRegressor | ||
|
||
from sklearn.model_selection import cross_val_score | ||
from ..datasets import diabetes_data | ||
|
||
from .._base_regression import BaseRegression | ||
|
||
|
||
class KNeighborsRegressorFunction(BaseRegression): | ||
name = "KNeighbors Regressor Function" | ||
_name_ = "k_neighbors_regressor" | ||
__name__ = "KNeighborsRegressorFunction" | ||
|
||
para_names = ["n_neighbors", "algorithm", "cv", "dataset"] | ||
|
||
n_neighbors_default = list(np.arange(3, 150, 5)) | ||
algorithm_default = ["auto", "ball_tree", "kd_tree", "brute"] | ||
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 search_space( | ||
self, | ||
n_neighbors: list = None, | ||
algorithm: list = None, | ||
cv: list = None, | ||
dataset: list = None, | ||
): | ||
search_space: dict = {} | ||
|
||
search_space["n_neighbors"] = ( | ||
self.n_neighbors_default if n_neighbors is None else n_neighbors | ||
) | ||
search_space["algorithm"] = ( | ||
self.algorithm_default if algorithm is None else algorithm | ||
) | ||
search_space["cv"] = self.cv_default if cv is None else cv | ||
search_space["dataset"] = self.dataset_default if dataset is None else dataset | ||
|
||
return search_space | ||
|
||
def create_objective_function(self): | ||
def k_neighbors_regressor(params): | ||
knc = KNeighborsRegressor( | ||
n_neighbors=params["n_neighbors"], | ||
algorithm=params["algorithm"], | ||
) | ||
X, y = params["dataset"]() | ||
scores = cross_val_score(knc, X, y, cv=params["cv"], scoring=self.metric) | ||
return scores.mean() | ||
|
||
self.pure_objective_function = k_neighbors_regressor |
Oops, something went wrong.