-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathothers.py
118 lines (83 loc) · 3.5 KB
/
others.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
import itertools
import os
from globals import *
import pandas as pd
from tensorflow.keras.callbacks import Callback
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
import matplotlib as mpl
import matplotlib.cm as cm
# =============================================================================
# RMSE : ROOT MEAN SQUARE ERROR
# =============================================================================
def RMSE(y_true, y_pred):
import numpy as np
if len(y_true) != len(y_pred):
print('dimensioni di y_true e y_pred non consistenti')
season = len(y_true)
se = np.square(y_true - y_pred)
rmse = np.sqrt((1 / season) * np.sum(se))
return rmse
# =============================================================================
# MAPE : MEAN ABSOLUTE PERCENTAGE ERROR
# =============================================================================
def MAPE(y_true, y_pred):
import numpy as np
if len(y_true) != len(y_pred):
print('dimensioni di y_true e y_pred non consistenti')
ae = np.absolute(y_true - y_pred)
ape = np.absolute(ae / y_true)
mape = np.mean(ape)
return mape
def get_unique_configs(det_layers1, det_hidden_sizes1):
assert len(det_layers1) == len(det_hidden_sizes1)
hyperparameters_list = []
configs = []
for lay1, hid1 in zip(det_layers1, det_hidden_sizes1):
configs.append([lay1,hid1])
configs_t = tuple(configs)
unique_configs = []
for counter, value in enumerate(configs_t):
temp_config = list(configs_t)
temp_config.pop(counter)
if (value in temp_config) and (value in unique_configs):
pass
else:
unique_configs.append(value)
unique_configs = tuple(unique_configs)
print('-----------------------------------------------------------------------')
print('The following configurations will be evaluated:')
for config in unique_configs:
print(str(config))
print('-----------------------------------------------------------------------')
return unique_configs
def evaluate_config_metrics(path_run):
train_mse_list = []
train_mae_list = []
train_mape_list = []
vali_mse_list = []
vali_mae_list = []
vali_mape_list = []
test_mse_list = []
test_mae_list = []
test_mape_list = []
for hour in range(24):
df_metrics = pd.read_csv(os.path.join(path_run, 'H_' + str(hour), 'metrics.csv'))
train_mse_list.append(df_metrics['MSE'][df_metrics['#'] == 'TRAIN_AVG'].values)
train_mae_list.append(df_metrics['MAE'][df_metrics['#'] == 'TRAIN_AVG'].values)
train_mape_list.append(df_metrics['MAPE'][df_metrics['#'] == 'TRAIN_AVG'].values)
vali_mse_list.append(df_metrics['MSE'][df_metrics['#'] == 'VALI_AVG'].values)
vali_mae_list.append(df_metrics['MAE'][df_metrics['#'] == 'VALI_AVG'].values)
vali_mape_list.append(df_metrics['MAPE'][df_metrics['#'] == 'VALI_AVG'].values)
test_mse_list.append(df_metrics['MSE'][df_metrics['#'] == 'TEST'].values)
test_mae_list.append(df_metrics['MAE'][df_metrics['#'] == 'TEST'].values)
test_mape_list.append(df_metrics['MAPE'][df_metrics['#'] == 'TEST'].values)
with open(os.path.join(path_run, 'metrics.csv'),'w') as f:
buffer = ','.join(['#','MSE','MAE','MAPE']) + '\n' + \
','.join(['TRAIN_AVG', str(np.mean(train_mse_list)), str(np.mean(train_mae_list)), str(np.mean(train_mape_list))]) + '\n' + \
','.join(['VALI_AVG', str(np.mean(vali_mse_list)), str(np.mean(vali_mae_list)), str(np.mean(vali_mape_list))]) + '\n' + \
','.join(['TEST_AVG', str(np.mean(test_mse_list)), str(np.mean(test_mae_list)), str(np.mean(test_mape_list))])
f.write(buffer)
f.close()
# TODO: evaluate hourly metrics