Skip to content

Commit 883d627

Browse files
author
Github Actions
committed
Ravin Kohli: Final changes for v0.1.0 (#341)
1 parent bec0fc3 commit 883d627

57 files changed

Lines changed: 1823 additions & 2551 deletions

File tree

Some content is hidden

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

master/_downloads/307f532dbef0476f85afc6b64b65f087/example_resampling_strategy.py

Lines changed: 30 additions & 12 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,27 +67,34 @@
6467

6568
############################################################################
6669
# Print the final ensemble performance
67-
# ====================================
68-
print(api.run_history, api.trajectory)
70+
# ------------------------------------
6971
y_pred = api.predict(X_test)
7072
score = api.score(y_pred, y_test)
7173
print(score)
7274
# Print the final ensemble built by AutoPyTorch
7375
print(api.show_models())
7476

77+
# Print statistics from search
78+
print(api.sprint_statistics())
79+
7580
############################################################################
7681

82+
############################################################################
83+
# Cross validation Resampling Strategy
84+
# =====================================
85+
7786
############################################################################
7887
# Build and fit a classifier with Cross validation resampling strategy
79-
# ====================================================================
88+
# --------------------------------------------------------------------
8089
api = TabularClassificationTask(
8190
resampling_strategy=CrossValTypes.k_fold_cross_validation,
8291
resampling_strategy_args={'num_splits': 3}
8392
)
8493

8594
############################################################################
8695
# Search for an ensemble of machine learning algorithms
87-
# =====================================================
96+
# -----------------------------------------------------------------------
97+
8898
api.search(
8999
X_train=X_train,
90100
y_train=y_train,
@@ -97,19 +107,25 @@
97107

98108
############################################################################
99109
# Print the final ensemble performance
100-
# ====================================
101-
print(api.run_history, api.trajectory)
110+
# ------------
102111
y_pred = api.predict(X_test)
103112
score = api.score(y_pred, y_test)
104113
print(score)
105114
# Print the final ensemble built by AutoPyTorch
106115
print(api.show_models())
107116

117+
# Print statistics from search
118+
print(api.sprint_statistics())
119+
108120
############################################################################
109121

122+
############################################################################
123+
# Stratified Resampling Strategy
124+
# ===============================
125+
110126
############################################################################
111127
# Build and fit a classifier with Stratified resampling strategy
112-
# ==============================================================
128+
# --------------------------------------------------------------
113129
api = TabularClassificationTask(
114130
# For demonstration purposes, we use
115131
# Stratified hold out validation. However,
@@ -120,7 +136,7 @@
120136

121137
############################################################################
122138
# Search for an ensemble of machine learning algorithms
123-
# =====================================================
139+
# -----------------------------------------------------
124140
api.search(
125141
X_train=X_train,
126142
y_train=y_train,
@@ -134,9 +150,11 @@
134150
############################################################################
135151
# Print the final ensemble performance
136152
# ====================================
137-
print(api.run_history, api.trajectory)
138153
y_pred = api.predict(X_test)
139154
score = api.score(y_pred, y_test)
140155
print(score)
141156
# Print the final ensemble built by AutoPyTorch
142157
print(api.show_models())
158+
159+
# Print statistics from search
160+
print(api.sprint_statistics())

master/_downloads/38ebc52de63d1626596d1647c695c721/example_tabular_regression.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
},
9999
"outputs": [],
100100
"source": [
101-
"print(api.run_history, api.trajectory)\ny_pred = api.predict(X_test)\n\n# Rescale the Neural Network predictions into the original target range\nscore = api.score(y_pred, y_test)\n\nprint(score)\n# Print the final ensemble built by AutoPyTorch\nprint(api.show_models())"
101+
"y_pred = api.predict(X_test)\n\n# Rescale the Neural Network predictions into the original target range\nscore = api.score(y_pred, y_test)\n\nprint(score)\n# Print the final ensemble built by AutoPyTorch\nprint(api.show_models())\n\n# Print statistics from search\nprint(api.sprint_statistics())"
102102
]
103103
}
104104
],

master/_downloads/3b0b756ccfcac69e6a1673e56f2f543f/example_visualization.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
},
9999
"outputs": [],
100100
"source": [
101-
"# We will plot the search incumbent through time.\n\n# Collect the performance of individual machine learning algorithms\n# found by SMAC\nindividual_performances = []\nfor run_key, run_value in estimator.run_history.data.items():\n if run_value.status != StatusType.SUCCESS:\n # Ignore crashed runs\n continue\n individual_performances.append({\n 'Timestamp': pd.Timestamp(\n time.strftime(\n '%Y-%m-%d %H:%M:%S',\n time.localtime(run_value.endtime)\n )\n ),\n 'single_best_optimization_accuracy': accuracy._optimum - run_value.cost,\n 'single_best_test_accuracy': np.nan if run_value.additional_info is None else\n accuracy._optimum - run_value.additional_info['test_loss'],\n })\nindividual_performance_frame = pd.DataFrame(individual_performances)\n\n# Collect the performance of the ensemble through time\n# This ensemble is built from the machine learning algorithms\n# found by SMAC\nensemble_performance_frame = pd.DataFrame(estimator.ensemble_performance_history)\n\n# As we are tracking the incumbent, we are interested in the cummax() performance\nensemble_performance_frame['ensemble_optimization_accuracy'] = ensemble_performance_frame[\n 'train_accuracy'\n].cummax()\nensemble_performance_frame['ensemble_test_accuracy'] = ensemble_performance_frame[\n 'test_accuracy'\n].cummax()\nensemble_performance_frame.drop(columns=['test_accuracy', 'train_accuracy'], inplace=True)\nindividual_performance_frame['single_best_optimization_accuracy'] = individual_performance_frame[\n 'single_best_optimization_accuracy'\n].cummax()\nindividual_performance_frame['single_best_test_accuracy'] = individual_performance_frame[\n 'single_best_test_accuracy'\n].cummax()\n\npd.merge(\n ensemble_performance_frame,\n individual_performance_frame,\n on=\"Timestamp\", how='outer'\n).sort_values('Timestamp').fillna(method='ffill').plot(\n x='Timestamp',\n kind='line',\n legend=True,\n title='Auto-PyTorch accuracy over time',\n grid=True,\n)\nplt.show()\n\n# We then can understand the importance of each input feature using\n# a permutation importance analysis. This is done as a proof of concept, to\n# showcase that we can leverage of scikit-learn API.\nresult = permutation_importance(estimator, X_train, y_train, n_repeats=5,\n scoring='accuracy',\n random_state=seed)\nsorted_idx = result.importances_mean.argsort()\n\nfig, ax = plt.subplots()\nax.boxplot(result.importances[sorted_idx].T,\n vert=False, labels=X_test.columns[sorted_idx])\nax.set_title(\"Permutation Importances (Train set)\")\nfig.tight_layout()\nplt.show()"
101+
"# We will plot the search incumbent through time.\n\n# Collect the performance of individual machine learning algorithms\n# found by SMAC\nindividual_performances = []\nfor run_key, run_value in estimator.run_history.data.items():\n if run_value.status != StatusType.SUCCESS:\n # Ignore crashed runs\n continue\n individual_performances.append({\n 'Timestamp': pd.Timestamp(\n time.strftime(\n '%Y-%m-%d %H:%M:%S',\n time.localtime(run_value.endtime)\n )\n ),\n 'single_best_optimization_accuracy': accuracy._optimum - run_value.cost,\n 'single_best_test_accuracy': np.nan if run_value.additional_info is None else\n accuracy._optimum - run_value.additional_info['test_loss']['accuracy'],\n })\nindividual_performance_frame = pd.DataFrame(individual_performances)\n\n# Collect the performance of the ensemble through time\n# This ensemble is built from the machine learning algorithms\n# found by SMAC\nensemble_performance_frame = pd.DataFrame(estimator.ensemble_performance_history)\n\n# As we are tracking the incumbent, we are interested in the cummax() performance\nensemble_performance_frame['ensemble_optimization_accuracy'] = ensemble_performance_frame[\n 'train_accuracy'\n].cummax()\nensemble_performance_frame['ensemble_test_accuracy'] = ensemble_performance_frame[\n 'test_accuracy'\n].cummax()\nensemble_performance_frame.drop(columns=['test_accuracy', 'train_accuracy'], inplace=True)\nindividual_performance_frame['single_best_optimization_accuracy'] = individual_performance_frame[\n 'single_best_optimization_accuracy'\n].cummax()\nindividual_performance_frame['single_best_test_accuracy'] = individual_performance_frame[\n 'single_best_test_accuracy'\n].cummax()\n\npd.merge(\n ensemble_performance_frame,\n individual_performance_frame,\n on=\"Timestamp\", how='outer'\n).sort_values('Timestamp').fillna(method='ffill').plot(\n x='Timestamp',\n kind='line',\n legend=True,\n title='Auto-PyTorch accuracy over time',\n grid=True,\n)\nplt.show()\n\n# We then can understand the importance of each input feature using\n# a permutation importance analysis. This is done as a proof of concept, to\n# showcase that we can leverage of scikit-learn API.\nresult = permutation_importance(estimator, X_train, y_train, n_repeats=5,\n scoring='accuracy',\n random_state=seed)\nsorted_idx = result.importances_mean.argsort()\n\nfig, ax = plt.subplots()\nax.boxplot(result.importances[sorted_idx].T,\n vert=False, labels=X_test.columns[sorted_idx])\nax.set_title(\"Permutation Importances (Train set)\")\nfig.tight_layout()\nplt.show()"
102102
]
103103
}
104104
],

0 commit comments

Comments
 (0)