Skip to content

Commit

Permalink
Merge pull request #128 from perib/new_search_space_def
Browse files Browse the repository at this point in the history
New search space def
  • Loading branch information
perib authored Apr 19, 2024
2 parents 5448a43 + 05c9ee5 commit 1710152
Show file tree
Hide file tree
Showing 12 changed files with 689 additions and 296 deletions.
436 changes: 436 additions & 0 deletions Tutorial/2_Search_Spaces.ipynb

Large diffs are not rendered by default.

42 changes: 40 additions & 2 deletions tpot2/config/classifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from ConfigSpace import EqualsCondition, OrConjunction, NotEqualsCondition, InCondition
from ..search_spaces.nodes.estimator_node import NONE_SPECIAL_STRING, TRUE_SPECIAL_STRING, FALSE_SPECIAL_STRING
import numpy as np

import sklearn


#TODO Conditional search space to prevent invalid combinations of hyperparameters
Expand Down Expand Up @@ -438,4 +438,42 @@ def MLPClassifier_hyperparameter_parser(params):
'learning_rate': params['learning_rate'],
'early_stopping': params['early_stopping'],
}
return hyperparameters
return hyperparameters

###


###

def get_GaussianProcessClassifier_ConfigurationSpace(n_features, random_state):
space = {
'n_features': n_features,
'alpha': Float("alpha", bounds=(1e-14, 1.0), log=True),
'thetaL': Float("thetaL", bounds=(1e-10, 1e-3), log=True),
'thetaU': Float("thetaU", bounds=(1.0, 100000), log=True),
}

if random_state is not None: #This is required because configspace doesn't allow None as a value
space['random_state'] = random_state

return ConfigurationSpace(
space = space
)

def GaussianProcessClassifier_hyperparameter_parser(params):
kernel = sklearn.gaussian_process.kernels.RBF(
length_scale = [1.0]*params['n_features'],
length_scale_bounds=[(params['thetaL'], params['thetaU'])] * params['n_features'],
)
final_params = {"kernel": kernel,
"alpha": params['alpha'],
"n_restarts_optimizer": 10,
"optimizer": "fmin_l_bfgs_b",
"normalize_y": True,
"copy_X_train": True,
}

if "random_state" in params:
final_params['random_state'] = params['random_state']

return final_params
13 changes: 9 additions & 4 deletions tpot2/config/get_configspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@
from sklearn.linear_model import PassiveAggressiveClassifier
from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis
from sklearn.linear_model import ARDRegression
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process import GaussianProcessRegressor, GaussianProcessClassifier

from sklearn.gaussian_process import GaussianProcessRegressor

from xgboost import XGBRegressor

Expand All @@ -113,6 +112,7 @@
AddTransformer, mul_neg_1_Transformer, MulTransformer, SafeReciprocalTransformer, EQTransformer, NETransformer, GETransformer, GTTransformer, LETransformer, LTTransformer, MinTransformer, MaxTransformer, ZeroTransformer, OneTransformer, NTransformer,
PowerTransformer, QuantileTransformer,ARDRegression, QuadraticDiscriminantAnalysis, PassiveAggressiveClassifier, LinearDiscriminantAnalysis,
DominantEncoder, RecessiveEncoder, HeterosisEncoder, UnderDominanceEncoder, OverDominanceEncoder,
GaussianProcessClassifier,
]


Expand Down Expand Up @@ -168,7 +168,7 @@
"selectors": ["SelectFwe", "SelectPercentile", "VarianceThreshold",],
"selectors_classification": ["SelectFwe", "SelectPercentile", "VarianceThreshold", "RFE_classification", "SelectFromModel_classification"],
"selectors_regression": ["SelectFwe", "SelectPercentile", "VarianceThreshold", "RFE_regression", "SelectFromModel_regression"],
"classifiers" : ['AdaBoostClassifier', 'BernoulliNB', 'DecisionTreeClassifier', 'ExtraTreesClassifier', 'GaussianNB', 'HistGradientBoostingClassifier', 'KNeighborsClassifier','LinearDiscriminantAnalysis', 'LogisticRegression', "LinearSVC", "SVC", 'MLPClassifier', 'MultinomialNB', "PassiveAggressiveClassifier", "QuadraticDiscriminantAnalysis", 'RandomForestClassifier', 'SGDClassifier', 'XGBClassifier'],
"classifiers" : ["GaussianProcessClassifier", 'AdaBoostClassifier', 'BernoulliNB', 'DecisionTreeClassifier', 'ExtraTreesClassifier', 'GaussianNB', 'HistGradientBoostingClassifier', 'KNeighborsClassifier','LinearDiscriminantAnalysis', 'LogisticRegression', "LinearSVC", "SVC", 'MLPClassifier', 'MultinomialNB', "PassiveAggressiveClassifier", "QuadraticDiscriminantAnalysis", 'RandomForestClassifier', 'SGDClassifier', 'XGBClassifier'],
"regressors" : ['AdaBoostRegressor', "ARDRegression", 'DecisionTreeRegressor', 'ExtraTreesRegressor', 'GaussianProcessRegressor', 'HistGradientBoostingRegressor', 'KNeighborsRegressor', 'LinearSVR', "MLPRegressor", 'RandomForestRegressor', 'SGDRegressor', 'SVR', 'XGBRegressor'],


Expand Down Expand Up @@ -252,6 +252,8 @@ def get_configspace(name, n_classes=3, n_samples=100, n_features=100, random_sta
return classifiers.get_PassiveAggressiveClassifier_ConfigurationSpace(random_state=random_state)
case "QuadraticDiscriminantAnalysis":
return classifiers.get_QuadraticDiscriminantAnalysis_ConfigurationSpace()
case "GaussianProcessClassifier":
return classifiers.get_GaussianProcessClassifier_ConfigurationSpace(n_features=n_features, random_state=random_state)

#regressors.py
case "RandomForestRegressor":
Expand Down Expand Up @@ -498,11 +500,14 @@ def get_node(name, n_classes=3, n_samples=100, n_features=100, random_state=None
if name == "GaussianProcessRegressor":
configspace = get_configspace(name, n_classes=n_classes, n_samples=n_samples, random_state=random_state)
return EstimatorNode(STRING_TO_CLASS[name], configspace, hyperparameter_parser=regressors.GaussianProcessRegressor_hyperparameter_parser)
if name == "GaussianProcessClassifier":
configspace = get_configspace(name, n_classes=n_classes, n_samples=n_samples, random_state=random_state)
return EstimatorNode(STRING_TO_CLASS[name], configspace, hyperparameter_parser=classifiers.GaussianProcessClassifier_hyperparameter_parser)

configspace = get_configspace(name, n_classes=n_classes, n_samples=n_samples, n_features=n_features, random_state=random_state)
if configspace is None:
#raise warning
warnings.warn(f"Could not find configspace for {name}")
return None

return EstimatorNode(STRING_TO_CLASS[name], configspace)
return EstimatorNode(STRING_TO_CLASS[name], configspace)
Loading

0 comments on commit 1710152

Please sign in to comment.