-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmlhandler-template.html
257 lines (246 loc) · 8.62 KB
/
mlhandler-template.html
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>{{ handler.name }}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.scss">
<link rel="stylesheet" href="ui/bootstrap-select/dist/css/bootstrap-select.min.css">
</head>
<style>
@keyframes donut-chart-fill {
to { stroke-dasharray: 0 100; }
}
body {
font-size: 16px;
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
color: #333;
}
.svg-item {
width: 200px;
height: 200px;
font-size: 16px;
}
.donut-ring {
stroke: #EBEBEB;
}
.donut-segment {
animation: donut-chart-fill 1s reverse ease-in;
transform-origin: center;
}
.donut-text {
font-family: Arial, Helvetica, sans-serif;
}
.donut-percent {
font-size: 0.5em;
line-height: 1;
fill: #000000
transform: translateY(0.5em);
}
</style>
<body>
{% set base = '.' %}
{% include template-navbar.html %}
{% set MODELS = [
'LogisticRegression',
'BernoulliNB',
'Perceptron',
'PassiveAggressiveClassifier',
'SVC',
'NuSVC',
'LinearSVC',
'KNeighborsClassifier',
'GaussianNB',
'DecisionTreeClassifier',
'RandomForestClassifier',
'MLPClassifier'] %}
{% set columns = data.columns.tolist() %}
{% set tcol = handler.get_opt('target_col', False) %}
{% set columns = columns + [tcol] %}
<!-- TODO: Filter bars -->
<div class="container-fluid py-4">
<div class="formhandler"></div>
<form class="form" id="train">
<div class="container">
<div class="row">
<div class="col">
<label for="exclude">Columns to Exclude:</label>
<select id="exclude" class="selectpicker form-control" multiple name="exclude">
{% for col in columns %}
{% set selected = "selected" if col in handler.get_opt('exclude', []) else "" %}
<option value="{{ col }}" {{ selected }}>{{ col }}</option>
{% end %}
</select>
</div>
<div class="col">
<label for="cats">Categorical Columns:</label>
<select id="exclude" class="selectpicker form-control" multiple name="cats">
{% for col in columns %}
{% set selected = "selected" if col in handler.get_opt('cats', []) else "" %}
<option value="{{ col }}" {{ selected }}>{{ col }}</option>
{% end %}
</select>
</div>
</div>
<div class="row pb-3 pt-3">
<div class="col">
<label for="targetcol">Pick a Target Column:</label>
<select id="targetcol" class="form-control" name="target_col">
{% for col in columns %}
{% set selected = "selected" if col == handler.get_opt('target_col') else "" %}
<option value="{{ col }}" {{ selected }}>{{ col }}</option>
{% end %}
</select>
</div>
<div class="col">
<label for="modelchoice">Pick a Model:</label>
<select id="modelchoice" class="form-control" name="class">
{% for model in MODELS %}
{% set selected = "selected" if model == handler.get_opt('class') else "" %}
<option value="{{ model }}" {{ selected }}>{{ model }}</option>
{% end %}
</select>
</div>
</div>
<div class="text-right">
<button class="btn btn-primary" type="submit">Train</button>
</div>
</div>
</form>
<div class="text-center divider">Results</div>
<div class="container" id="resultcnt">
<div class="row">
<div class="col">
<div class="text-center">
<strong>Your model scored</strong>
</div>
<div class="text-center">
<svg width="20%" height="20%" viewBox="0 0 40 40" class="donut">
<circle class="donut-hole" cx="20" cy="20" r="15.91549430918954" fill="#fff"></circle>
<circle class="donut-ring" cx="20" cy="20" r="15.91549430918954" fill="transparent" stroke-width="3.5"></circle>
<circle class="donut-segment" cx="20" cy="20" r="15.91549430918954" fill="transparent" stroke-width="3.5" stroke-dasharray="10 90" stroke-dashoffset="25"></circle>
<g class="donut-text">
<text y="50%" transform="translate(0, 2)">
<tspan x="50%" text-anchor="middle" class="donut-percent">40%</tspan>
</text>
</g>
</svg>
</div>
</div>
<div class="col">
<div class="row">
<form id="testform" enctype="multipart/form-data">
<div class="row pb-3">
<label for="testurl">
Happy with the result? <a id="downlink">Download the model.</a> Or get predictions:
</label>
<input name="file" type="file" id="testurl" class="form-control">
</div>
<div class="text-right">
<button id="testbtn" class="btn btn-primary" type="submit">Predict</button>
</div>
</form>
</div>
<div class="row">
<a class="ml-auto" id="downloadbtn">Download Predictions</a>
</div>
</div>
</div>
</div>
</div><!-- .container-fluid -->
<script src="ui/jquery/dist/jquery.min.js"></script>
<script src="ui/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="ui/d3v5/dist/d3.min.js"></script>
<script src="ui/lodash/lodash.min.js"></script>
<script src="ui/morphdom/dist/morphdom-umd.min.js"></script>
<script src="ui/g1/dist/g1.min.js"></script>
<script src="ui/bootstrap-select/dist/js/bootstrap-select.min.js"></script>
<!-- Commonly used libraries:
<script src="ui/dayjs/dayjs.min.js"></script>
<script src="ui/daterangepicker/daterangepicker.js"></script>
<script src="ui/leaflet/dist/leaflet.js"></script>
<script src="ui/topojson/dist/topojson.min.js"></script>
-->
</body>
<script>
$.fn.selectpicker.Constructor.BootstrapVersion = '4';
var opts = null
const get_score_color = function(s) {
let color = "#ff0000"
if (s > 50) { color = "#f7b100"}
if (s > 90) { color = "#00f700" }
return color
}
const post_train = function (target_col) {
$('#resultcnt').hide()
$.ajax({
url: g1.url.parse(window.location) + "?_action=retrain&target_col=" + encodeURIComponent(target_col),
method: 'POST',
success: function(resp) {
let score = Number.parseFloat(JSON.parse(resp).score * 100).toPrecision(4)
score = Number.parseFloat(score)
$('.donut-segment').attr('stroke-dasharray', `${score} ${100 - score}`)
$('tspan').html(`${score}%`)
$('.donut-segment').attr('stroke', get_score_color(score))
$('#resultcnt').show()
}
})
}
$(document).ready(function() {
$('#downloadbtn').hide()
$('#resultcnt').hide()
let url = g1.url.parse(window.location)
url.search = '_cache'
$('.formhandler').attr('data-src', url.toString())
$('.formhandler').formhandler({
pageSize: 5,
export: false
})
url.search = '_cache&_opts'
$.getJSON(url.toString()).done(function (e) { opts = e })
url.search = "_model&_download"
$('#downlink').attr('href', url.toString())
// Select
$('.selectpicker').selectpicker({
actionsBox: true
})
$('#train').submit(function(e) {
e.preventDefault()
let fd = new FormData(this)
let trainUrl = g1.url.parse(window.location + '?_model')
trainUrl.update({class: fd.get('class')})
trainUrl.update({exclude: fd.getAll('exclude')})
trainUrl.update({cats: fd.getAll('cats')})
$.ajax({
url: trainUrl.toString(),
method: 'PUT',
success: function() {
post_train(fd.get('target_col'))
}
})
})
$('#testform').submit(function(e) {
e.preventDefault()
let fd = new FormData(this)
let testUrl = g1.url.parse(window.location)
testUrl.search = '_action=predict'
$.ajax({
url: testUrl.toString(),
method: 'POST',
data: fd,
processData: false,
contentType: false,
success: function(resp) {
$('#downloadbtn').show()
$('#downloadbtn').attr('href', 'data:text/json;charset=utf-8,' + encodeURIComponent(resp))
$('#downloadbtn').attr('download', 'predictions.json')
$('#downloadbtn').attr('_target', '_blank')
}
})
})
})
</script>
</html>