-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
144 lines (101 loc) · 4.44 KB
/
main.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#
# main.py
# Jonathan Pilault, 2016-08-01
# Copyright (c) 2016 mldb.ai inc. All rights reserved.
#
########################
# Variable definitions #
########################
# Only change in main.py
mode = "categorical" # "boolean", "categorical"
allowable_models = ["bbdt_d5", "bbs2", "bglz", "dt"] # ["bbdt_d5", "bbs2", "bglz", "dt", "glz"]
unique_labels = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
########################
# Function definitions #
########################
def get_mode():
global mode
return mode
def get_models():
global allowable_models
return allowable_models
def get_allowed_labels():
global unique_labels
return unique_labels
########################
######## Main ########
########################
if __name__ == '__main__':
mldb.plugin.serve_static_folder('/static', 'static')
mldb = mldb_wrapper.wrap(mldb)
base_model_url = "file://" + mldb.plugin.get_plugin_dir() + "/models/"
mldb.log("Loading Main.py...")
# Get test set for sending pics in the front-end
data_url_mnist = 'http://public.mldb.ai/datasets/digits_data.csv.gz'
print mldb.put('/v1/procedures/import_digits_mnist', {
"type":"import.text",
"params": {
"dataFileUrl": data_url_mnist,
"outputDataset": "digits_mnist",
"select": "{* EXCLUDING(\"785\")} AS *, \"785\" AS label",
"runOnCreation": True,
"where": "rowHash() % 5 = 0"
}
})
for model in allowable_models:
modelFileUrlPattern = base_model_url + model
run_again = True
for target in unique_labels:
_model = "_" + model
_mode = "_" + mode
procedureRunName = "mnist" + _model + _mode
if (mode == "categorical"):
_target = ""
if (mode == "boolean"):
_target = "_" + str(target)
run_again = True # "boolean" runs for each target while categorical runs only once
mldb.log("********************* %s *********************" % (procedureRunName + _target))
if (run_again):
#############################
# Check/Create Explain #
#############################
try:
conf_explain = {
"id": "explain_%s" % (procedureRunName + _target),
"type": "classifier.explain",
"params": { "modelFileUrl": "%s/%s.cls" % (modelFileUrlPattern, (procedureRunName + _target))}
}
create_explain = mldb.put("/v1/functions/explain_%s" % (procedureRunName + _target), conf_explain)
mldb.log(create_explain)
mldb.log("explain_%s created" % (procedureRunName + _target))
except Exception as xcpt:
mldb.log(xcpt)
#############################
# Check/Create Scorer #
#############################
try:
conf_score = {
"id": "%s_scorer_0" % (procedureRunName + _target),
"type": "classifier",
"params": { "modelFileUrl": "%s/%s.cls" % (modelFileUrlPattern, (procedureRunName + _target))}
}
create_score = mldb.put("/v1/functions/%s_scorer_0" % (procedureRunName + _target), conf_score)
mldb.log(create_score)
mldb.log("%s_scorer_0" % (procedureRunName + _target))
run_again = False # "boolean" runs for each target while categorical runs only once
except Exception as xcpt:
mldb.log(xcpt)
#############################
# Check/Create Probabilizer #
#############################
_target_prob = "_" + str(target)
try:
conf_proba = {
"id": "probabilizer_%s" % (procedureRunName + _target_prob),
"type": "probabilizer",
"params": { "modelFileUrl": "%s/probabilizer_%s.cls" % (modelFileUrlPattern, (procedureRunName + _target_prob))}
}
create_probabilizer = mldb.put("/v1/functions/probabilizer_%s" % (procedureRunName + _target_prob), conf_proba)
mldb.log(create_probabilizer)
except Exception as xcpt:
mldb.log(xcpt)