Skip to content

Commit 79c1953

Browse files
authored
Merge pull request #684 from openml/update_examples
Added notice to all examples for using the test server. Use test serv…
2 parents 2b35edc + c31e6ed commit 79c1953

8 files changed

Lines changed: 61 additions & 22 deletions

doc/conf.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@
1717
import sphinx_bootstrap_theme
1818
import openml
1919

20-
21-
# amueller's read/write key
22-
openml.config.server = "https://test.openml.org/api/v1/xml"
23-
openml.config.apikey = "610344db6388d9ba34f6db45a3cf71de"
24-
25-
2620
# If extensions (or modules to document with autodoc) are in another directory,
2721
# add these directories to sys.path here. If the directory is relative to the
2822
# documentation root, use os.path.abspath to make it absolute, like shown here.

examples/create_upload_tutorial.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313
from openml.datasets.functions import create_dataset
1414

1515
############################################################################
16-
# For this tutorial we will upload to the test server to not pollute the live
17-
# server with countless copies of the same dataset.
18-
openml.config.server = 'https://test.openml.org/api/v1/xml'
16+
# .. warning:: This example uploads data. For that reason, this example
17+
# connects to the test server at test.openml.org. This prevents the main
18+
# server from crowding with example datasets, tasks, runs, and so on.
19+
20+
openml.config.start_using_configuration_for_example()
21+
############################################################################
1922

2023
############################################################################
2124
# Below we will cover the following cases of the dataset object:
@@ -309,3 +312,7 @@
309312

310313
upload_did = xor_dataset.publish()
311314
print('URL for dataset: %s/data/%d' % (openml.config.server, upload_did))
315+
316+
317+
############################################################################
318+
openml.config.stop_using_configuration_for_example()

examples/datasets_tutorial.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
How to list and download datasets.
77
"""
8-
8+
############################################################################
99
import openml
1010
import pandas as pd
1111

@@ -43,9 +43,8 @@
4343
# Download datasets
4444
# =================
4545

46-
# This is done based on the dataset ID ('did').
47-
dataset = openml.datasets.get_dataset(68)
48-
# NOTE: Dataset 68 exists on the test server https://test.openml.org/d/68
46+
# This is done based on the dataset ID.
47+
dataset = openml.datasets.get_dataset(1471)
4948

5049
# Print a summary
5150
print("This is dataset '%s', the target feature is '%s'" %
@@ -84,8 +83,7 @@
8483
# data file. The dataset object can be used as normal.
8584
# Whenever you use any functionality that requires the data,
8685
# such as `get_data`, the data will be downloaded.
87-
dataset = openml.datasets.get_dataset(68, download_data=False)
88-
# NOTE: Dataset 68 exists on the test server https://test.openml.org/d/68
86+
dataset = openml.datasets.get_dataset(1471, download_data=False)
8987

9088
############################################################################
9189
# Exercise 2

examples/flows_and_runs_tutorial.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@
1414
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1515
#
1616
# Train a scikit-learn model on the data manually.
17+
#
18+
# .. warning:: This example uploads data. For that reason, this example
19+
# connects to the test server at test.openml.org. This prevents the main
20+
# server from crowding with example datasets, tasks, runs, and so on.
1721

18-
# NOTE: Dataset 68 exists on the test server https://test.openml.org/d/68
22+
openml.config.start_using_configuration_for_example()
23+
# NOTE: We are using dataset 68 from the test server: https://test.openml.org/d/68
1924
dataset = openml.datasets.get_dataset(68)
2025
X, y = dataset.get_data(
2126
dataset_format='array',
@@ -159,3 +164,7 @@
159164
run = openml.runs.run_model_on_task(clf, task, avoid_duplicate_runs=False)
160165
myrun = run.publish()
161166
print("kNN on %s: http://test.openml.org/r/%d" % (data.name, myrun.run_id))
167+
168+
169+
############################################################################
170+
openml.config.stop_using_configuration_for_example()

examples/introduction_tutorial.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,21 @@
4545
# file must be in the directory ~/.openml/config and exist prior to
4646
# importing the openml module.
4747
# * Run the code below, replacing 'YOURKEY' with your API key.
48-
48+
#
49+
# .. warning:: This example uploads data. For that reason, this example
50+
# connects to the test server instead. This prevents the live server from
51+
# crowding with example datasets, tasks, studies, and so on.
4952
############################################################################
5053
import openml
5154
from sklearn import neighbors
5255

53-
# Uncomment and set your OpenML key. Don't share your key with others.
56+
openml.config.start_using_configuration_for_example()
57+
58+
############################################################################
59+
# When using the main server, instead make sure your apikey is configured.
60+
# This can be done with the following line of code (uncomment it!).
61+
# Never share your apikey with others.
62+
5463
# openml.config.apikey = 'YOURKEY'
5564

5665
############################################################################
@@ -80,6 +89,9 @@
8089
run = openml.runs.run_model_on_task(clf, task, avoid_duplicate_runs=False)
8190
# Publish the experiment on OpenML (optional, requires an API key).
8291
# For this tutorial, our configuration publishes to the test server
83-
# as to not pollute the main server.
92+
# as to not crowd the main server with runs created by examples.
8493
myrun = run.publish()
8594
print("kNN on %s: http://test.openml.org/r/%d" % (data.name, myrun.run_id))
95+
96+
############################################################################
97+
openml.config.stop_using_configuration_for_example()

examples/run_setup_tutorial.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
and solve the same task again;
2626
3) We will verify that the obtained results are exactly the same.
2727
28+
.. warning:: This example uploads data. For that reason, this example
29+
connects to the test server at test.openml.org. This prevents the main
30+
server from crowding with example datasets, tasks, runs, and so on.
2831
"""
2932
import logging
3033
import numpy as np
@@ -36,6 +39,7 @@
3639

3740
root = logging.getLogger()
3841
root.setLevel(logging.INFO)
42+
openml.config.start_using_configuration_for_example()
3943

4044
###############################################################################
4145
# 1) Create a flow and use it to solve a task
@@ -100,3 +104,7 @@
100104
# the run has stored all predictions in the field data content
101105
np.testing.assert_array_equal(run_original.data_content,
102106
run_duplicate.data_content)
107+
108+
###############################################################################
109+
110+
openml.config.stop_using_configuration_for_example()

examples/sklearn/openml_run_example.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
import openml
88
from sklearn import tree, preprocessing, pipeline
99

10+
############################################################################
11+
# .. warning:: This example uploads data. For that reason, this example
12+
# connects to the test server at test.openml.org. This prevents the main
13+
# server from crowding with example datasets, tasks, runs, and so on.
14+
15+
openml.config.start_using_configuration_for_example()
16+
############################################################################
17+
1018
# Uncomment and set your OpenML key. Don't share your key with others.
1119
# openml.config.apikey = 'YOURKEY'
1220

@@ -27,3 +35,6 @@
2735
run.publish()
2836

2937
print('URL for run: %s/run/%d' % (openml.config.server, run.run_id))
38+
39+
############################################################################
40+
openml.config.stop_using_configuration_for_example()

examples/tasks_tutorial.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
############################################################################
8080
# Furthermore, we can list tasks based on the dataset id:
8181

82-
tasks = openml.tasks.list_tasks(data_id=61)
82+
tasks = openml.tasks.list_tasks(data_id=1471)
8383
tasks = pd.DataFrame.from_dict(tasks, orient='index')
8484
print("First 5 of %s tasks:" % len(tasks))
8585
pprint(tasks.head())
@@ -124,7 +124,7 @@
124124
# single task by its ID, and one which takes a list of IDs and downloads
125125
# all of these tasks:
126126

127-
task_id = 1
127+
task_id = 31
128128
task = openml.tasks.get_task(task_id)
129129

130130
############################################################################
@@ -135,6 +135,6 @@
135135
############################################################################
136136
# And:
137137

138-
ids = [1, 2, 19, 97, 403]
138+
ids = [2, 1891, 31, 9983]
139139
tasks = openml.tasks.get_tasks(ids)
140140
pprint(tasks[0])

0 commit comments

Comments
 (0)