-
Notifications
You must be signed in to change notification settings - Fork 8
/
sagemaker.py
53 lines (37 loc) · 1.32 KB
/
sagemaker.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
import json
from dateutil.relativedelta import relativedelta
from data_load import get_parts_series, get_elec_series
def write_inference(filename, datetime_offset, s):
instances = []
for i in range(len(s)):
instances.append({
'start': str(datetime_offset),
'target': list(s[i])
})
configuration = {
"num_samples": 50,
"output_types": ["mean", "quantiles", "samples"],
"quantiles": ["0.5", "0.9"]
}
with open(filename, 'w') as f:
f.write(json.dumps({
'instances': instances,
'configuration': configuration
}))
def write_file(filename, datetime_offset, s):
with open(filename, 'w') as f:
for i in range(len(s)):
f.write(json.dumps({
'start': str(datetime_offset),
'target': list(s[i])
}) + '\n')
if __name__ == '__main__':
offset_train, s = get_elec_series()
_, T = s.shape
enc_len = 168
dec_len = 24
offset_valid = offset_train + relativedelta(hours=T - dec_len - enc_len)
write_file('data/sagemaker_train.json', offset_train, s[:, :-dec_len])
write_file('data/sagemaker_valid.json', offset_train, s)
write_inference('data/inference.json', offset_valid, s[:, -(enc_len + dec_len):-dec_len])
print('finished')