-
-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathstudy_tutorial.py
103 lines (81 loc) · 3.14 KB
/
study_tutorial.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"""
=================
Benchmark studies
=================
How to list, download and upload benchmark studies.
In contrast to `benchmark suites <https://docs.openml.org/benchmark/#benchmarking-suites>`_ which
hold a list of tasks, studies hold a list of runs. As runs contain all information on flows and
tasks, all required information about a study can be retrieved.
"""
############################################################################
# License: BSD 3-Clause
import uuid
from sklearn.ensemble import RandomForestClassifier
import openml
############################################################################
# Listing studies
# ***************
studies = openml.study.list_studies(status="all")
print(studies.head(n=10))
############################################################################
# Downloading studies
# ===================
############################################################################
# This is done based on the study ID.
study = openml.study.get_study(123)
print(study)
############################################################################
# Studies also features a description:
print(study.description)
############################################################################
# Studies are a container for runs:
print(study.runs)
############################################################################
# And we can use the evaluation listing functionality to learn more about
# the evaluations available for the conducted runs:
evaluations = openml.evaluations.list_evaluations(
function="predictive_accuracy",
study=study.study_id,
)
print(evaluations.head())
############################################################################
# We'll use the test server for the rest of this tutorial.
#
# .. warning::
# .. include:: ../../test_server_usage_warning.txt
openml.config.start_using_configuration_for_example()
############################################################################
# Uploading studies
# =================
#
# Creating a study is as simple as creating any kind of other OpenML entity.
# In this examples we'll create a few runs for the OpenML-100 benchmark
# suite which is available on the OpenML test server.
# Model to be used
clf = RandomForestClassifier()
# We'll create a study with one run on 3 datasets present in the suite
tasks = [115, 259, 307]
# To verify
# https://test.openml.org/api/v1/study/1
suite = openml.study.get_suite("OpenML100")
print(all(t_id in suite.tasks for t_id in tasks))
run_ids = []
for task_id in tasks:
task = openml.tasks.get_task(task_id)
run = openml.runs.run_model_on_task(clf, task)
run.publish()
run_ids.append(run.run_id)
# The study needs a machine-readable and unique alias. To obtain this,
# we simply generate a random uuid.
alias = uuid.uuid4().hex
new_study = openml.study.create_study(
name="Test-Study",
description="Test study for the Python tutorial on studies",
run_ids=run_ids,
alias=alias,
benchmark_suite=suite.study_id,
)
new_study.publish()
print(new_study)
############################################################################
openml.config.stop_using_configuration_for_example()