Skip to content

Commit 7521dd1

Browse files
author
Github Actions
committed
Francisco Rivera Valverde: Remove the __main__ restriction from examples (#1053)
1 parent afb0ac1 commit 7521dd1

File tree

100 files changed

+10292
-5733
lines changed

Some content is hidden

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

100 files changed

+10292
-5733
lines changed

development/_downloads/16fb4037a0b549292dbf3df70af70372/example_classification.ipynb

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,79 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"import sklearn.datasets\nimport sklearn.metrics\n\nimport autosklearn.classification\n\n\nif __name__ == \"__main__\":\n ############################################################################\n # Data Loading\n # ============\n\n X, y = sklearn.datasets.load_breast_cancer(return_X_y=True)\n X_train, X_test, y_train, y_test = \\\n sklearn.model_selection.train_test_split(X, y, random_state=1)\n\n ############################################################################\n # Build and fit a regressor\n # =========================\n\n automl = autosklearn.classification.AutoSklearnClassifier(\n time_left_for_this_task=120,\n per_run_time_limit=30,\n tmp_folder='/tmp/autosklearn_classification_example_tmp',\n output_folder='/tmp/autosklearn_classification_example_out',\n )\n automl.fit(X_train, y_train, dataset_name='breast_cancer')\n\n ############################################################################\n # Print the final ensemble constructed by auto-sklearn\n # ====================================================\n\n print(automl.show_models())\n\n ###########################################################################\n # Get the Score of the final ensemble\n # ===================================\n\n predictions = automl.predict(X_test)\n print(\"Accuracy score:\", sklearn.metrics.accuracy_score(y_test, predictions))"
29+
"import sklearn.datasets\nimport sklearn.metrics\n\nimport autosklearn.classification"
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.load_breast_cancer(return_X_y=True)\nX_train, X_test, y_train, y_test = \\\n sklearn.model_selection.train_test_split(X, y, random_state=1)"
48+
]
49+
},
50+
{
51+
"cell_type": "markdown",
52+
"metadata": {},
53+
"source": [
54+
"## Build and fit a regressor\n\n"
55+
]
56+
},
57+
{
58+
"cell_type": "code",
59+
"execution_count": null,
60+
"metadata": {
61+
"collapsed": false
62+
},
63+
"outputs": [],
64+
"source": [
65+
"automl = autosklearn.classification.AutoSklearnClassifier(\n time_left_for_this_task=120,\n per_run_time_limit=30,\n tmp_folder='/tmp/autosklearn_classification_example_tmp',\n output_folder='/tmp/autosklearn_classification_example_out',\n)\nautoml.fit(X_train, y_train, dataset_name='breast_cancer')"
66+
]
67+
},
68+
{
69+
"cell_type": "markdown",
70+
"metadata": {},
71+
"source": [
72+
"## Print the final ensemble constructed by auto-sklearn\n\n"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": null,
78+
"metadata": {
79+
"collapsed": false
80+
},
81+
"outputs": [],
82+
"source": [
83+
"print(automl.show_models())"
84+
]
85+
},
86+
{
87+
"cell_type": "markdown",
88+
"metadata": {},
89+
"source": [
90+
"## Get the Score of the final ensemble\n\n"
91+
]
92+
},
93+
{
94+
"cell_type": "code",
95+
"execution_count": null,
96+
"metadata": {
97+
"collapsed": false
98+
},
99+
"outputs": [],
100+
"source": [
101+
"predictions = automl.predict(X_test)\nprint(\"Accuracy score:\", sklearn.metrics.accuracy_score(y_test, predictions))"
30102
]
31103
}
32104
],

development/_downloads/1a053e45a20a2c15032411b9fee890a3/example_sequential.py

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,45 @@
1616
import autosklearn.classification
1717

1818

19-
if __name__ == "__main__":
20-
############################################################################
21-
# Data Loading
22-
# ======================================
23-
24-
X, y = sklearn.datasets.load_breast_cancer(return_X_y=True)
25-
X_train, X_test, y_train, y_test = \
26-
sklearn.model_selection.train_test_split(X, y, random_state=1)
27-
28-
############################################################################
29-
# Build and fit the classifier
30-
# ======================================
31-
32-
automl = autosklearn.classification.AutoSklearnClassifier(
33-
time_left_for_this_task=120,
34-
per_run_time_limit=30,
35-
tmp_folder='/tmp/autosklearn_sequential_example_tmp',
36-
output_folder='/tmp/autosklearn_sequential_example_out',
37-
# Do not construct ensembles in parallel to avoid using more than one
38-
# core at a time. The ensemble will be constructed after auto-sklearn
39-
# finished fitting all machine learning models.
40-
ensemble_size=0,
41-
delete_tmp_folder_after_terminate=False,
42-
)
43-
automl.fit(X_train, y_train, dataset_name='breast_cancer')
44-
45-
# This call to fit_ensemble uses all models trained in the previous call
46-
# to fit to build an ensemble which can be used with automl.predict()
47-
automl.fit_ensemble(y_train, ensemble_size=50)
48-
49-
############################################################################
50-
# Print the final ensemble constructed by auto-sklearn
51-
# ====================================================
52-
53-
print(automl.show_models())
54-
55-
############################################################################
56-
# Get the Score of the final ensemble
57-
# ===================================
58-
59-
predictions = automl.predict(X_test)
60-
print(automl.sprint_statistics())
61-
print("Accuracy score", sklearn.metrics.accuracy_score(y_test, predictions))
19+
############################################################################
20+
# Data Loading
21+
# ======================================
22+
23+
X, y = sklearn.datasets.load_breast_cancer(return_X_y=True)
24+
X_train, X_test, y_train, y_test = \
25+
sklearn.model_selection.train_test_split(X, y, random_state=1)
26+
27+
############################################################################
28+
# Build and fit the classifier
29+
# ======================================
30+
31+
automl = autosklearn.classification.AutoSklearnClassifier(
32+
time_left_for_this_task=120,
33+
per_run_time_limit=30,
34+
tmp_folder='/tmp/autosklearn_sequential_example_tmp',
35+
output_folder='/tmp/autosklearn_sequential_example_out',
36+
# Do not construct ensembles in parallel to avoid using more than one
37+
# core at a time. The ensemble will be constructed after auto-sklearn
38+
# finished fitting all machine learning models.
39+
ensemble_size=0,
40+
delete_tmp_folder_after_terminate=False,
41+
)
42+
automl.fit(X_train, y_train, dataset_name='breast_cancer')
43+
44+
# This call to fit_ensemble uses all models trained in the previous call
45+
# to fit to build an ensemble which can be used with automl.predict()
46+
automl.fit_ensemble(y_train, ensemble_size=50)
47+
48+
############################################################################
49+
# Print the final ensemble constructed by auto-sklearn
50+
# ====================================================
51+
52+
print(automl.show_models())
53+
54+
############################################################################
55+
# Get the Score of the final ensemble
56+
# ===================================
57+
58+
predictions = automl.predict(X_test)
59+
print(automl.sprint_statistics())
60+
print("Accuracy score", sklearn.metrics.accuracy_score(y_test, predictions))

0 commit comments

Comments
 (0)