|
5 | 5 |
|
6 | 6 | The following example shows how adjust the configuration space of
|
7 | 7 | the search. Currently, there are two changes that can be made to the space:-
|
| 8 | +
|
8 | 9 | 1. Adjust individual hyperparameters in the pipeline
|
9 | 10 | 2. Include or exclude components:
|
10 | 11 | a) include: Dictionary containing components to include. Key is the node
|
@@ -57,80 +58,78 @@ def get_search_space_updates():
|
57 | 58 | return updates
|
58 | 59 |
|
59 | 60 |
|
60 |
| -if __name__ == '__main__': |
61 |
| - |
62 |
| - ############################################################################ |
63 |
| - # Data Loading |
64 |
| - # ============ |
65 |
| - X, y = sklearn.datasets.fetch_openml(data_id=40981, return_X_y=True, as_frame=True) |
66 |
| - X_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split( |
67 |
| - X, |
68 |
| - y, |
69 |
| - random_state=1, |
70 |
| - ) |
71 |
| - |
72 |
| - ############################################################################ |
73 |
| - # Build and fit a classifier with include components |
74 |
| - # ================================================== |
75 |
| - api = TabularClassificationTask( |
76 |
| - search_space_updates=get_search_space_updates(), |
77 |
| - include_components={'network_backbone': ['MLPBackbone', 'ResNetBackbone'], |
78 |
| - 'encoder': ['OneHotEncoder']} |
79 |
| - ) |
80 |
| - |
81 |
| - ############################################################################ |
82 |
| - # Search for an ensemble of machine learning algorithms |
83 |
| - # ===================================================== |
84 |
| - api.search( |
85 |
| - X_train=X_train.copy(), |
86 |
| - y_train=y_train.copy(), |
87 |
| - X_test=X_test.copy(), |
88 |
| - y_test=y_test.copy(), |
89 |
| - optimize_metric='accuracy', |
90 |
| - total_walltime_limit=150, |
91 |
| - func_eval_time_limit_secs=30 |
92 |
| - ) |
93 |
| - |
94 |
| - ############################################################################ |
95 |
| - # Print the final ensemble performance |
96 |
| - # ==================================== |
97 |
| - y_pred = api.predict(X_test) |
98 |
| - score = api.score(y_pred, y_test) |
99 |
| - print(score) |
100 |
| - print(api.show_models()) |
101 |
| - |
102 |
| - # Print statistics from search |
103 |
| - print(api.sprint_statistics()) |
104 |
| - |
105 |
| - ############################################################################ |
106 |
| - # Build and fit a classifier with exclude components |
107 |
| - # ================================================== |
108 |
| - api = TabularClassificationTask( |
109 |
| - search_space_updates=get_search_space_updates(), |
110 |
| - exclude_components={'network_backbone': ['MLPBackbone'], |
111 |
| - 'encoder': ['OneHotEncoder']} |
112 |
| - ) |
113 |
| - |
114 |
| - ############################################################################ |
115 |
| - # Search for an ensemble of machine learning algorithms |
116 |
| - # ===================================================== |
117 |
| - api.search( |
118 |
| - X_train=X_train, |
119 |
| - y_train=y_train, |
120 |
| - X_test=X_test.copy(), |
121 |
| - y_test=y_test.copy(), |
122 |
| - optimize_metric='accuracy', |
123 |
| - total_walltime_limit=150, |
124 |
| - func_eval_time_limit_secs=30 |
125 |
| - ) |
126 |
| - |
127 |
| - ############################################################################ |
128 |
| - # Print the final ensemble performance |
129 |
| - # ==================================== |
130 |
| - y_pred = api.predict(X_test) |
131 |
| - score = api.score(y_pred, y_test) |
132 |
| - print(score) |
133 |
| - print(api.show_models()) |
134 |
| - |
135 |
| - # Print statistics from search |
136 |
| - print(api.sprint_statistics()) |
| 61 | +############################################################################ |
| 62 | +# Data Loading |
| 63 | +# ============ |
| 64 | +X, y = sklearn.datasets.fetch_openml(data_id=40981, return_X_y=True, as_frame=True) |
| 65 | +X_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split( |
| 66 | + X, |
| 67 | + y, |
| 68 | + random_state=1, |
| 69 | +) |
| 70 | + |
| 71 | +############################################################################ |
| 72 | +# Build and fit a classifier with include components |
| 73 | +# ================================================== |
| 74 | +api = TabularClassificationTask( |
| 75 | + search_space_updates=get_search_space_updates(), |
| 76 | + include_components={'network_backbone': ['MLPBackbone', 'ResNetBackbone'], |
| 77 | + 'encoder': ['OneHotEncoder']} |
| 78 | +) |
| 79 | + |
| 80 | +############################################################################ |
| 81 | +# Search for an ensemble of machine learning algorithms |
| 82 | +# ===================================================== |
| 83 | +api.search( |
| 84 | + X_train=X_train.copy(), |
| 85 | + y_train=y_train.copy(), |
| 86 | + X_test=X_test.copy(), |
| 87 | + y_test=y_test.copy(), |
| 88 | + optimize_metric='accuracy', |
| 89 | + total_walltime_limit=150, |
| 90 | + func_eval_time_limit_secs=30 |
| 91 | +) |
| 92 | + |
| 93 | +############################################################################ |
| 94 | +# Print the final ensemble performance |
| 95 | +# ==================================== |
| 96 | +y_pred = api.predict(X_test) |
| 97 | +score = api.score(y_pred, y_test) |
| 98 | +print(score) |
| 99 | +print(api.show_models()) |
| 100 | + |
| 101 | +# Print statistics from search |
| 102 | +print(api.sprint_statistics()) |
| 103 | + |
| 104 | +############################################################################ |
| 105 | +# Build and fit a classifier with exclude components |
| 106 | +# ================================================== |
| 107 | +api = TabularClassificationTask( |
| 108 | + search_space_updates=get_search_space_updates(), |
| 109 | + exclude_components={'network_backbone': ['MLPBackbone'], |
| 110 | + 'encoder': ['OneHotEncoder']} |
| 111 | +) |
| 112 | + |
| 113 | +############################################################################ |
| 114 | +# Search for an ensemble of machine learning algorithms |
| 115 | +# ===================================================== |
| 116 | +api.search( |
| 117 | + X_train=X_train, |
| 118 | + y_train=y_train, |
| 119 | + X_test=X_test.copy(), |
| 120 | + y_test=y_test.copy(), |
| 121 | + optimize_metric='accuracy', |
| 122 | + total_walltime_limit=150, |
| 123 | + func_eval_time_limit_secs=30 |
| 124 | +) |
| 125 | + |
| 126 | +############################################################################ |
| 127 | +# Print the final ensemble performance |
| 128 | +# ==================================== |
| 129 | +y_pred = api.predict(X_test) |
| 130 | +score = api.score(y_pred, y_test) |
| 131 | +print(score) |
| 132 | +print(api.show_models()) |
| 133 | + |
| 134 | +# Print statistics from search |
| 135 | +print(api.sprint_statistics()) |
0 commit comments