forked from openml/openml-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_clustering_task.py
More file actions
62 lines (53 loc) · 2.28 KB
/
test_clustering_task.py
File metadata and controls
62 lines (53 loc) · 2.28 KB
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
# License: BSD 3-Clause
import openml
from openml.testing import TestBase
from .test_task import OpenMLTaskTest
from openml.exceptions import OpenMLServerException
class OpenMLClusteringTaskTest(OpenMLTaskTest):
__test__ = True
def setUp(self, n_levels: int = 1):
super(OpenMLClusteringTaskTest, self).setUp()
self.task_id = 146714
self.task_type_id = 5
self.estimation_procedure = 17
def test_get_dataset(self):
# no clustering tasks on test server
openml.config.server = self.production_server
task = openml.tasks.get_task(self.task_id)
task.get_dataset()
def test_download_task(self):
# no clustering tasks on test server
openml.config.server = self.production_server
task = super(OpenMLClusteringTaskTest, self).test_download_task()
self.assertEqual(task.task_id, self.task_id)
self.assertEqual(task.task_type_id, 5)
self.assertEqual(task.dataset_id, 36)
def test_upload_task(self):
compatible_datasets = self._get_compatible_rand_dataset()
for i in range(100):
try:
dataset_id = compatible_datasets[i % len(compatible_datasets)]
# Upload a clustering task without a ground truth.
task = openml.tasks.create_task(
task_type_id=self.task_type_id,
dataset_id=dataset_id,
estimation_procedure_id=self.estimation_procedure
)
task = task.publish()
TestBase._mark_entity_for_removal('task', task.id)
TestBase.logger.info("collected from {}: {}".format(__file__.split('/')[-1],
task.id))
# success
break
except OpenMLServerException as e:
# Error code for 'task already exists'
# Should be 533 according to the docs
# (# https://www.openml.org/api_docs#!/task/post_task)
if e.code == 614:
continue
else:
raise e
else:
raise ValueError(
'Could not create a valid task for task type ID {}'.format(self.task_type_id)
)