-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathevaluation.py
More file actions
36 lines (29 loc) · 1.09 KB
/
Copy pathevaluation.py
File metadata and controls
36 lines (29 loc) · 1.09 KB
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
import numpy as np
import pandas as pd
def mae(y, y_hat):
return np.nanmean(np.abs(y-y_hat))
def rmse(y, y_hat):
return np.sqrt(np.nanmean((y-y_hat)**2))
def mape(y, y_hat):
return np.nanmean(np.abs((y-y_hat)/y))
def smape(y, y_hat):
return np.nanmean(np.abs(y-y_hat)/ ((y+y_hat)*2))
def recover_dates(df):
dates = []
idx = 0
df_ = df.reset_index()
for i,traffic in enumerate(df_.iloc[start:end]['traffic_volume'].values):
if np.isnan(traffic):
continue
if ( (int(traffic) == int(Y[idx])) or
((int(traffic)-1) == int(Y[idx])) or
((int(traffic)+1) == int(Y[idx]))):
dates.append(df_.iloc[start+i].date_time)
idx += 1
return np.hstack(dates)
def get_df_with_dates(df, Y, Y_hat):
dates = recover_dates(Y, df)
df_fulldates = pd.DataFrame(pd.date_range(*dates[[0,-1]], freq='H'),columns=['date'])
df_original = pd.DataFrame(np.vstack([dates, Y, Y_hat]).T, columns=['date', 'y','y_pred'])
df_results = df_original.merge(df_fulldates, how='right').set_index('date')
return df_results