-
-
Notifications
You must be signed in to change notification settings - Fork 143
/
functions.py
47 lines (37 loc) · 1.51 KB
/
functions.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
import openml
import xmltodict
from collections import OrderedDict
def setup_exists(downloaded_flow, sklearn_model):
'''
Checks whether a flow / hyperparameter configuration already exists on the server
Parameter
---------
downloaded_flow : flow
the openml flow object (should be downloaded from server)
sklearn_model : BaseEstimator
The base estimator that was used to create the flow. Will
be used to extract parameter settings from.
Returns
-------
setup_id : int
setup id iff exists, False otherwise
'''
# sadly, this api call relies on a run object
openml_param_settings = openml.runs.OpenMLRun._parse_parameters(sklearn_model, downloaded_flow)
description = xmltodict.unparse(_to_dict(downloaded_flow.flow_id, openml_param_settings), pretty=True)
file_elements = {'description': ('description.arff',description)}
result = openml._api_calls._perform_api_call('/setup/exists/',
file_elements=file_elements)
result_dict = xmltodict.parse(result)
setup_id = int(result_dict['oml:setup_exists']['oml:id'])
if setup_id > 0:
return setup_id
else:
return False;
def _to_dict(flow_id, openml_parameter_settings):
xml = OrderedDict()
xml['oml:run'] = OrderedDict()
xml['oml:run']['@xmlns:oml'] = 'http://openml.org/openml'
xml['oml:run']['oml:flow_id'] = flow_id
xml['oml:run']['oml:parameter_setting'] = openml_parameter_settings
return xml