Skip to content

Commit

Permalink
Merge branch 'development' into reg_cocktails
Browse files Browse the repository at this point in the history
  • Loading branch information
ravinkohli committed Dec 10, 2021
2 parents 33b2223 + 40a3987 commit 9238a04
Showing 1 changed file with 76 additions and 73 deletions.
149 changes: 76 additions & 73 deletions examples/40_advanced/example_custom_configuration_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
The following example shows how adjust the configuration space of
the search. Currently, there are two changes that can be made to the space:-
1. Adjust individual hyperparameters in the pipeline
2. Include or exclude components:
a) include: Dictionary containing components to include. Key is the node
Expand Down Expand Up @@ -66,76 +67,78 @@ def get_search_space_updates():
return updates


if __name__ == '__main__':

############################################################################
# Data Loading
# ============
X, y = sklearn.datasets.fetch_openml(data_id=40981, return_X_y=True, as_frame=True)
X_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split(
X,
y,
random_state=1,
)

############################################################################
# Build and fit a classifier with include components
# ==================================================
api = TabularClassificationTask(
search_space_updates=get_search_space_updates(),
include_components={'network_backbone': ['ResNetBackbone'],
'encoder': ['OneHotEncoder']}
)

############################################################################
# Search for an ensemble of machine learning algorithms
# =====================================================
api.search(
X_train=X_train.copy(),
y_train=y_train.copy(),
X_test=X_test.copy(),
y_test=y_test.copy(),
optimize_metric='accuracy',
total_walltime_limit=300,
func_eval_time_limit_secs=50
)

############################################################################
# Print the final ensemble performance
# ====================================
print(api.run_history, api.trajectory)
y_pred = api.predict(X_test)
score = api.score(y_pred, y_test)
print(score)
print(api.show_models())

############################################################################
# Build and fit a classifier with exclude components
# ==================================================
api = TabularClassificationTask(
search_space_updates=get_search_space_updates(),
exclude_components={'network_backbone': ['MLPBackbone'],
'encoder': ['OneHotEncoder']}
)

############################################################################
# Search for an ensemble of machine learning algorithms
# =====================================================
api.search(
X_train=X_train,
y_train=y_train,
X_test=X_test.copy(),
y_test=y_test.copy(),
optimize_metric='accuracy',
total_walltime_limit=300,
func_eval_time_limit_secs=50
)

############################################################################
# Print the final ensemble performance
# ====================================
print(api.run_history, api.trajectory)
y_pred = api.predict(X_test)
score = api.score(y_pred, y_test)
print(score)
print(api.show_models())
############################################################################
# Data Loading
# ============
X, y = sklearn.datasets.fetch_openml(data_id=40981, return_X_y=True, as_frame=True)
X_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split(
X,
y,
random_state=1,
)

############################################################################
# Build and fit a classifier with include components
# ==================================================
api = TabularClassificationTask(
search_space_updates=get_search_space_updates(),
include_components={'network_backbone': ['MLPBackbone', 'ResNetBackbone'],
'encoder': ['OneHotEncoder']}
)

############################################################################
# Search for an ensemble of machine learning algorithms
# =====================================================
api.search(
X_train=X_train.copy(),
y_train=y_train.copy(),
X_test=X_test.copy(),
y_test=y_test.copy(),
optimize_metric='accuracy',
total_walltime_limit=150,
func_eval_time_limit_secs=30
)

############################################################################
# Print the final ensemble performance
# ====================================
y_pred = api.predict(X_test)
score = api.score(y_pred, y_test)
print(score)
print(api.show_models())

# Print statistics from search
print(api.sprint_statistics())

############################################################################
# Build and fit a classifier with exclude components
# ==================================================
api = TabularClassificationTask(
search_space_updates=get_search_space_updates(),
exclude_components={'network_backbone': ['MLPBackbone'],
'encoder': ['OneHotEncoder']}
)

############################################################################
# Search for an ensemble of machine learning algorithms
# =====================================================
api.search(
X_train=X_train,
y_train=y_train,
X_test=X_test.copy(),
y_test=y_test.copy(),
optimize_metric='accuracy',
total_walltime_limit=150,
func_eval_time_limit_secs=30
)

############################################################################
# Print the final ensemble performance
# ====================================
y_pred = api.predict(X_test)
score = api.score(y_pred, y_test)
print(score)
print(api.show_models())

# Print statistics from search
print(api.sprint_statistics())

0 comments on commit 9238a04

Please sign in to comment.