Skip to content

Commit 8c9a9c1

Browse files
author
Github Actions
committed
Ravin Kohli: [FIX formatting in docs (#342)
1 parent b64c977 commit 8c9a9c1

File tree

42 files changed

+1546
-1219
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1546
-1219
lines changed

development/_downloads/307f532dbef0476f85afc6b64b65f087/example_resampling_strategy.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@
2626
from autoPyTorch.api.tabular_classification import TabularClassificationTask
2727
from autoPyTorch.datasets.resampling_strategy import CrossValTypes, HoldoutValTypes
2828

29+
############################################################################
30+
# Default Resampling Strategy
31+
# ============================
2932

3033
############################################################################
3134
# Data Loading
32-
# ============
35+
# ------------
3336
X, y = sklearn.datasets.fetch_openml(data_id=40981, return_X_y=True, as_frame=True)
3437
X_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split(
3538
X,
@@ -39,7 +42,7 @@
3942

4043
############################################################################
4144
# Build and fit a classifier with default resampling strategy
42-
# ===========================================================
45+
# -----------------------------------------------------------
4346
api = TabularClassificationTask(
4447
# 'HoldoutValTypes.holdout_validation' with 'val_share': 0.33
4548
# is the default argument setting for TabularClassificationTask.
@@ -51,7 +54,7 @@
5154

5255
############################################################################
5356
# Search for an ensemble of machine learning algorithms
54-
# =====================================================
57+
# -----------------------------------------------------
5558
api.search(
5659
X_train=X_train,
5760
y_train=y_train,
@@ -64,7 +67,7 @@
6467

6568
############################################################################
6669
# Print the final ensemble performance
67-
# ====================================
70+
# ------------------------------------
6871
y_pred = api.predict(X_test)
6972
score = api.score(y_pred, y_test)
7073
print(score)
@@ -76,17 +79,22 @@
7679

7780
############################################################################
7881

82+
############################################################################
83+
# Cross validation Resampling Strategy
84+
# =====================================
85+
7986
############################################################################
8087
# Build and fit a classifier with Cross validation resampling strategy
81-
# ====================================================================
88+
# --------------------------------------------------------------------
8289
api = TabularClassificationTask(
8390
resampling_strategy=CrossValTypes.k_fold_cross_validation,
8491
resampling_strategy_args={'num_splits': 3}
8592
)
8693

8794
############################################################################
8895
# Search for an ensemble of machine learning algorithms
89-
# =====================================================
96+
# -----------------------------------------------------------------------
97+
9098
api.search(
9199
X_train=X_train,
92100
y_train=y_train,
@@ -99,7 +107,7 @@
99107

100108
############################################################################
101109
# Print the final ensemble performance
102-
# ====================================
110+
# ------------
103111
y_pred = api.predict(X_test)
104112
score = api.score(y_pred, y_test)
105113
print(score)
@@ -111,9 +119,13 @@
111119

112120
############################################################################
113121

122+
############################################################################
123+
# Stratified Resampling Strategy
124+
# ===============================
125+
114126
############################################################################
115127
# Build and fit a classifier with Stratified resampling strategy
116-
# ==============================================================
128+
# --------------------------------------------------------------
117129
api = TabularClassificationTask(
118130
# For demonstration purposes, we use
119131
# Stratified hold out validation. However,
@@ -124,7 +136,7 @@
124136

125137
############################################################################
126138
# Search for an ensemble of machine learning algorithms
127-
# =====================================================
139+
# -----------------------------------------------------
128140
api.search(
129141
X_train=X_train,
130142
y_train=y_train,

development/_downloads/3f9c66ebcc4532fdade3cdaa4d769bde/example_custom_configuration_space.ipynb

Lines changed: 128 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"cell_type": "markdown",
1616
"metadata": {},
1717
"source": [
18-
"\n# Tabular Classification with Custom Configuration Space\n\nThe following example shows how adjust the configuration space of\nthe search. Currently, there are two changes that can be made to the space:-\n1. Adjust individual hyperparameters in the pipeline\n2. Include or exclude components:\n a) include: Dictionary containing components to include. Key is the node\n name and Value is an Iterable of the names of the components\n to include. Only these components will be present in the\n search space.\n b) exclude: Dictionary containing components to exclude. Key is the node\n name and Value is an Iterable of the names of the components\n to exclude. All except these components will be present in\n the search space.\n"
18+
"\n# Tabular Classification with Custom Configuration Space\n\nThe following example shows how adjust the configuration space of\nthe search. Currently, there are two changes that can be made to the space:-\n\n1. Adjust individual hyperparameters in the pipeline\n2. Include or exclude components:\n a) include: Dictionary containing components to include. Key is the node\n name and Value is an Iterable of the names of the components\n to include. Only these components will be present in the\n search space.\n b) exclude: Dictionary containing components to exclude. Key is the node\n name and Value is an Iterable of the names of the components\n to exclude. All except these components will be present in\n the search space.\n"
1919
]
2020
},
2121
{
@@ -26,7 +26,133 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"import os\nimport tempfile as tmp\nimport warnings\n\nos.environ['JOBLIB_TEMP_FOLDER'] = tmp.gettempdir()\nos.environ['OMP_NUM_THREADS'] = '1'\nos.environ['OPENBLAS_NUM_THREADS'] = '1'\nos.environ['MKL_NUM_THREADS'] = '1'\n\nwarnings.simplefilter(action='ignore', category=UserWarning)\nwarnings.simplefilter(action='ignore', category=FutureWarning)\n\nimport sklearn.datasets\nimport sklearn.model_selection\n\nfrom autoPyTorch.api.tabular_classification import TabularClassificationTask\nfrom autoPyTorch.utils.hyperparameter_search_space_update import HyperparameterSearchSpaceUpdates\n\n\ndef get_search_space_updates():\n \"\"\"\n Search space updates to the task can be added using HyperparameterSearchSpaceUpdates\n Returns:\n HyperparameterSearchSpaceUpdates\n \"\"\"\n updates = HyperparameterSearchSpaceUpdates()\n updates.append(node_name=\"data_loader\",\n hyperparameter=\"batch_size\",\n value_range=[16, 512],\n default_value=32)\n updates.append(node_name=\"lr_scheduler\",\n hyperparameter=\"CosineAnnealingLR:T_max\",\n value_range=[50, 60],\n default_value=55)\n updates.append(node_name='network_backbone',\n hyperparameter='ResNetBackbone:dropout',\n value_range=[0, 0.5],\n default_value=0.2)\n return updates\n\n\nif __name__ == '__main__':\n\n ############################################################################\n # Data Loading\n # ============\n X, y = sklearn.datasets.fetch_openml(data_id=40981, return_X_y=True, as_frame=True)\n X_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split(\n X,\n y,\n random_state=1,\n )\n\n ############################################################################\n # Build and fit a classifier with include components\n # ==================================================\n api = TabularClassificationTask(\n search_space_updates=get_search_space_updates(),\n include_components={'network_backbone': ['MLPBackbone', 'ResNetBackbone'],\n 'encoder': ['OneHotEncoder']}\n )\n\n ############################################################################\n # Search for an ensemble of machine learning algorithms\n # =====================================================\n api.search(\n X_train=X_train.copy(),\n y_train=y_train.copy(),\n X_test=X_test.copy(),\n y_test=y_test.copy(),\n optimize_metric='accuracy',\n total_walltime_limit=150,\n func_eval_time_limit_secs=30\n )\n\n ############################################################################\n # Print the final ensemble performance\n # ====================================\n y_pred = api.predict(X_test)\n score = api.score(y_pred, y_test)\n print(score)\n print(api.show_models())\n\n # Print statistics from search\n print(api.sprint_statistics())\n\n ############################################################################\n # Build and fit a classifier with exclude components\n # ==================================================\n api = TabularClassificationTask(\n search_space_updates=get_search_space_updates(),\n exclude_components={'network_backbone': ['MLPBackbone'],\n 'encoder': ['OneHotEncoder']}\n )\n\n ############################################################################\n # Search for an ensemble of machine learning algorithms\n # =====================================================\n api.search(\n X_train=X_train,\n y_train=y_train,\n X_test=X_test.copy(),\n y_test=y_test.copy(),\n optimize_metric='accuracy',\n total_walltime_limit=150,\n func_eval_time_limit_secs=30\n )\n\n ############################################################################\n # Print the final ensemble performance\n # ====================================\n y_pred = api.predict(X_test)\n score = api.score(y_pred, y_test)\n print(score)\n print(api.show_models())\n\n # Print statistics from search\n print(api.sprint_statistics())"
29+
"import os\nimport tempfile as tmp\nimport warnings\n\nos.environ['JOBLIB_TEMP_FOLDER'] = tmp.gettempdir()\nos.environ['OMP_NUM_THREADS'] = '1'\nos.environ['OPENBLAS_NUM_THREADS'] = '1'\nos.environ['MKL_NUM_THREADS'] = '1'\n\nwarnings.simplefilter(action='ignore', category=UserWarning)\nwarnings.simplefilter(action='ignore', category=FutureWarning)\n\nimport sklearn.datasets\nimport sklearn.model_selection\n\nfrom autoPyTorch.api.tabular_classification import TabularClassificationTask\nfrom autoPyTorch.utils.hyperparameter_search_space_update import HyperparameterSearchSpaceUpdates\n\n\ndef get_search_space_updates():\n \"\"\"\n Search space updates to the task can be added using HyperparameterSearchSpaceUpdates\n Returns:\n HyperparameterSearchSpaceUpdates\n \"\"\"\n updates = HyperparameterSearchSpaceUpdates()\n updates.append(node_name=\"data_loader\",\n hyperparameter=\"batch_size\",\n value_range=[16, 512],\n default_value=32)\n updates.append(node_name=\"lr_scheduler\",\n hyperparameter=\"CosineAnnealingLR:T_max\",\n value_range=[50, 60],\n default_value=55)\n updates.append(node_name='network_backbone',\n hyperparameter='ResNetBackbone:dropout',\n value_range=[0, 0.5],\n default_value=0.2)\n return updates"
30+
]
31+
},
32+
{
33+
"cell_type": "markdown",
34+
"metadata": {},
35+
"source": [
36+
"## Data Loading\n\n"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": null,
42+
"metadata": {
43+
"collapsed": false
44+
},
45+
"outputs": [],
46+
"source": [
47+
"X, y = sklearn.datasets.fetch_openml(data_id=40981, return_X_y=True, as_frame=True)\nX_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split(\n X,\n y,\n random_state=1,\n)"
48+
]
49+
},
50+
{
51+
"cell_type": "markdown",
52+
"metadata": {},
53+
"source": [
54+
"## Build and fit a classifier with include components\n\n"
55+
]
56+
},
57+
{
58+
"cell_type": "code",
59+
"execution_count": null,
60+
"metadata": {
61+
"collapsed": false
62+
},
63+
"outputs": [],
64+
"source": [
65+
"api = TabularClassificationTask(\n search_space_updates=get_search_space_updates(),\n include_components={'network_backbone': ['MLPBackbone', 'ResNetBackbone'],\n 'encoder': ['OneHotEncoder']}\n)"
66+
]
67+
},
68+
{
69+
"cell_type": "markdown",
70+
"metadata": {},
71+
"source": [
72+
"## Search for an ensemble of machine learning algorithms\n\n"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": null,
78+
"metadata": {
79+
"collapsed": false
80+
},
81+
"outputs": [],
82+
"source": [
83+
"api.search(\n X_train=X_train.copy(),\n y_train=y_train.copy(),\n X_test=X_test.copy(),\n y_test=y_test.copy(),\n optimize_metric='accuracy',\n total_walltime_limit=150,\n func_eval_time_limit_secs=30\n)"
84+
]
85+
},
86+
{
87+
"cell_type": "markdown",
88+
"metadata": {},
89+
"source": [
90+
"## Print the final ensemble performance\n\n"
91+
]
92+
},
93+
{
94+
"cell_type": "code",
95+
"execution_count": null,
96+
"metadata": {
97+
"collapsed": false
98+
},
99+
"outputs": [],
100+
"source": [
101+
"y_pred = api.predict(X_test)\nscore = api.score(y_pred, y_test)\nprint(score)\nprint(api.show_models())\n\n# Print statistics from search\nprint(api.sprint_statistics())"
102+
]
103+
},
104+
{
105+
"cell_type": "markdown",
106+
"metadata": {},
107+
"source": [
108+
"## Build and fit a classifier with exclude components\n\n"
109+
]
110+
},
111+
{
112+
"cell_type": "code",
113+
"execution_count": null,
114+
"metadata": {
115+
"collapsed": false
116+
},
117+
"outputs": [],
118+
"source": [
119+
"api = TabularClassificationTask(\n search_space_updates=get_search_space_updates(),\n exclude_components={'network_backbone': ['MLPBackbone'],\n 'encoder': ['OneHotEncoder']}\n)"
120+
]
121+
},
122+
{
123+
"cell_type": "markdown",
124+
"metadata": {},
125+
"source": [
126+
"## Search for an ensemble of machine learning algorithms\n\n"
127+
]
128+
},
129+
{
130+
"cell_type": "code",
131+
"execution_count": null,
132+
"metadata": {
133+
"collapsed": false
134+
},
135+
"outputs": [],
136+
"source": [
137+
"api.search(\n X_train=X_train,\n y_train=y_train,\n X_test=X_test.copy(),\n y_test=y_test.copy(),\n optimize_metric='accuracy',\n total_walltime_limit=150,\n func_eval_time_limit_secs=30\n)"
138+
]
139+
},
140+
{
141+
"cell_type": "markdown",
142+
"metadata": {},
143+
"source": [
144+
"## Print the final ensemble performance\n\n"
145+
]
146+
},
147+
{
148+
"cell_type": "code",
149+
"execution_count": null,
150+
"metadata": {
151+
"collapsed": false
152+
},
153+
"outputs": [],
154+
"source": [
155+
"y_pred = api.predict(X_test)\nscore = api.score(y_pred, y_test)\nprint(score)\nprint(api.show_models())\n\n# Print statistics from search\nprint(api.sprint_statistics())"
30156
]
31157
}
32158
],

development/_downloads/4cbefcc88d68bf84110d315dc5fdb8e1/example_resampling_strategy.ipynb

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@
3333
"cell_type": "markdown",
3434
"metadata": {},
3535
"source": [
36-
"## Data Loading\n\n"
36+
"## Default Resampling Strategy\n\n"
37+
]
38+
},
39+
{
40+
"cell_type": "markdown",
41+
"metadata": {},
42+
"source": [
43+
"### Data Loading\n\n"
3744
]
3845
},
3946
{
@@ -51,7 +58,7 @@
5158
"cell_type": "markdown",
5259
"metadata": {},
5360
"source": [
54-
"## Build and fit a classifier with default resampling strategy\n\n"
61+
"### Build and fit a classifier with default resampling strategy\n\n"
5562
]
5663
},
5764
{
@@ -69,7 +76,7 @@
6976
"cell_type": "markdown",
7077
"metadata": {},
7178
"source": [
72-
"## Search for an ensemble of machine learning algorithms\n\n"
79+
"### Search for an ensemble of machine learning algorithms\n\n"
7380
]
7481
},
7582
{
@@ -87,7 +94,7 @@
8794
"cell_type": "markdown",
8895
"metadata": {},
8996
"source": [
90-
"## Print the final ensemble performance\n\n"
97+
"### Print the final ensemble performance\n\n"
9198
]
9299
},
93100
{
@@ -105,7 +112,14 @@
105112
"cell_type": "markdown",
106113
"metadata": {},
107114
"source": [
108-
"## Build and fit a classifier with Cross validation resampling strategy\n\n"
115+
"## Cross validation Resampling Strategy\n\n"
116+
]
117+
},
118+
{
119+
"cell_type": "markdown",
120+
"metadata": {},
121+
"source": [
122+
"### Build and fit a classifier with Cross validation resampling strategy\n\n"
109123
]
110124
},
111125
{
@@ -123,7 +137,7 @@
123137
"cell_type": "markdown",
124138
"metadata": {},
125139
"source": [
126-
"## Search for an ensemble of machine learning algorithms\n\n"
140+
"### Search for an ensemble of machine learning algorithms\n\n"
127141
]
128142
},
129143
{
@@ -141,7 +155,7 @@
141155
"cell_type": "markdown",
142156
"metadata": {},
143157
"source": [
144-
"## Print the final ensemble performance\n\n"
158+
"### Print the final ensemble performance\n\n"
145159
]
146160
},
147161
{
@@ -159,7 +173,14 @@
159173
"cell_type": "markdown",
160174
"metadata": {},
161175
"source": [
162-
"## Build and fit a classifier with Stratified resampling strategy\n\n"
176+
"## Stratified Resampling Strategy\n\n"
177+
]
178+
},
179+
{
180+
"cell_type": "markdown",
181+
"metadata": {},
182+
"source": [
183+
"### Build and fit a classifier with Stratified resampling strategy\n\n"
163184
]
164185
},
165186
{
@@ -177,7 +198,7 @@
177198
"cell_type": "markdown",
178199
"metadata": {},
179200
"source": [
180-
"## Search for an ensemble of machine learning algorithms\n\n"
201+
"### Search for an ensemble of machine learning algorithms\n\n"
181202
]
182203
},
183204
{

0 commit comments

Comments
 (0)