Skip to content

Commit be0ba3e

Browse files
committed
[FIX formatting in docs (#342)
* fix formatting in docs * Update examples/40_advanced/example_resampling_strategy.py Update README.md, remove cat requirements.txt
1 parent 49e846e commit be0ba3e

5 files changed

+144
-135
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ git submodule update --init --recursive
5656
conda create -n auto-pytorch python=3.8
5757
conda activate auto-pytorch
5858
conda install swig
59-
cat requirements.txt | xargs -n 1 -L 1 pip install
6059
python setup.py install
6160

6261
```

examples/40_advanced/example_custom_configuration_space.py

Lines changed: 76 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
The following example shows how adjust the configuration space of
77
the search. Currently, there are two changes that can be made to the space:-
8+
89
1. Adjust individual hyperparameters in the pipeline
910
2. Include or exclude components:
1011
a) include: Dictionary containing components to include. Key is the node
@@ -57,80 +58,78 @@ def get_search_space_updates():
5758
return updates
5859

5960

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())

examples/40_advanced/example_parallel_n_jobs.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""
2-
======================
3-
Tabular Classification
4-
======================
2+
============================================
3+
Tabular Classification with n parallel jobs
4+
============================================
55
66
The following example shows how to fit a sample classification model parallely on 2 cores
77
with AutoPyTorch
8+
89
"""
910
import os
1011
import tempfile as tmp
@@ -60,9 +61,9 @@
6061
############################################################################
6162
# Print the final ensemble performance
6263
# ====================================
63-
print(api.run_history, api.trajectory)
6464
y_pred = api.predict(X_test)
6565
score = api.score(y_pred, y_test)
6666
print(score)
6767
# Print the final ensemble built by AutoPyTorch
68-
print(api.show_models())
68+
print(api.sprint_statistics())
69+

examples/40_advanced/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,

examples/40_advanced/example_run_with_portfolio.py

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -24,50 +24,48 @@
2424
from autoPyTorch.api.tabular_classification import TabularClassificationTask
2525

2626

27-
if __name__ == '__main__':
27+
############################################################################
28+
# Data Loading
29+
# ============
30+
X, y = sklearn.datasets.fetch_openml(data_id=40981, return_X_y=True, as_frame=True)
31+
X_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split(
32+
X,
33+
y,
34+
random_state=42,
35+
)
2836

29-
############################################################################
30-
# Data Loading
31-
# ============
32-
X, y = sklearn.datasets.fetch_openml(data_id=40981, return_X_y=True, as_frame=True)
33-
X_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split(
34-
X,
35-
y,
36-
random_state=42,
37-
)
37+
############################################################################
38+
# Build and fit a classifier
39+
# ==========================
40+
api = TabularClassificationTask(
41+
seed=42,
42+
)
3843

39-
############################################################################
40-
# Build and fit a classifier
41-
# ==========================
42-
api = TabularClassificationTask(
43-
seed=42,
44-
)
44+
############################################################################
45+
# Search for an ensemble of machine learning algorithms
46+
# =====================================================
47+
api.search(
48+
X_train=X_train,
49+
y_train=y_train,
50+
X_test=X_test.copy(),
51+
y_test=y_test.copy(),
52+
optimize_metric='accuracy',
53+
total_walltime_limit=300,
54+
func_eval_time_limit_secs=50,
55+
# Setting this option to "greedy"
56+
# will make smac run the configurations
57+
# present in 'autoPyTorch/configs/greedy_portfolio.json'
58+
portfolio_selection="greedy"
59+
)
4560

46-
############################################################################
47-
# Search for an ensemble of machine learning algorithms
48-
# =====================================================
49-
api.search(
50-
X_train=X_train,
51-
y_train=y_train,
52-
X_test=X_test.copy(),
53-
y_test=y_test.copy(),
54-
optimize_metric='accuracy',
55-
total_walltime_limit=300,
56-
func_eval_time_limit_secs=50,
57-
# Setting this option to "greedy"
58-
# will make smac run the configurations
59-
# present in 'autoPyTorch/configs/greedy_portfolio.json'
60-
portfolio_selection="greedy"
61-
)
61+
############################################################################
62+
# Print the final ensemble performance
63+
# ====================================
64+
y_pred = api.predict(X_test)
65+
score = api.score(y_pred, y_test)
66+
print(score)
67+
# Print the final ensemble built by AutoPyTorch
68+
print(api.show_models())
6269

63-
############################################################################
64-
# Print the final ensemble performance
65-
# ====================================
66-
y_pred = api.predict(X_test)
67-
score = api.score(y_pred, y_test)
68-
print(score)
69-
# Print the final ensemble built by AutoPyTorch
70-
print(api.show_models())
71-
72-
# Print statistics from search
73-
print(api.sprint_statistics())
70+
# Print statistics from search
71+
print(api.sprint_statistics())

0 commit comments

Comments
 (0)