-
Notifications
You must be signed in to change notification settings - Fork 27
/
evaluation.py
67 lines (54 loc) · 1.99 KB
/
evaluation.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
from pathlib import Path
import pickle
import argparse
import numpy as np
from src.losses.numpy import mae, mse
def get_score_min_val(dir):
print(dir)
result = pickle.load(open(dir, 'rb'))
min_mae = 100
mc = {}
for i in range(len(result)):
val_mae = result.trials[i]['result']['loss']
if val_mae < min_mae:
mae_best = result.trials[i]['result']['test_losses']['mae']
mse_best = result.trials[i]['result']['test_losses']['mse']
min_mae = val_mae
mc = result.trials[i]['result']['mc']
return mae_best, mse_best, mc
def main(args):
if args.horizon<0:
if args.dataset == 'ili':
horizons = [24, 36, 48, 60]
else:
horizons = [96, 192, 336, 720]
else:
horizons = [args.horizon]
for horizon in horizons:
result_dir = f'./results/{args.setting}/{args.dataset}_{horizon}/{args.model}/'
result_dir = Path(result_dir)
files = list(result_dir.glob(f'hyperopt_{args.experiment}*.p'))
maes = []
mses = []
for file_ in files:
mae_data, mse_data = get_score_min_val(file_)
maes.append(mae_data)
mses.append(mse_data)
print(f'Horizon {horizon}')
print(f'MSE: {np.mean(mses)}')
print(f'MAE: {np.mean(maes)}')
def parse_args():
desc = "Example of hyperparameter tuning"
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('--dataset', type=str, help='Name of the dataset')
parser.add_argument('--setting', type=str, help='Multivariate or univariate', default='multivariate')
parser.add_argument('--horizon', type=int, help='Horizon')
parser.add_argument('--model', type=str, help='Model name')
parser.add_argument('--experiment', type=str, help='string to identify experiment')
return parser.parse_args()
if __name__ == '__main__':
# parse arguments
args = parse_args()
if args is None:
exit()
main(args)