#constructing daily error dataframe days = predictions.groupby( [predictions.index.year, predictions.index.month, predictions.index.day]).count().index.values rush_hour_predictions = predictions[(predictions.index.hour > 15) & (predictions.index.hour < 22)] daily_error = [] rush_hour_error = [] for day in days: day_real = predictions[predictions.index.day == day[2]]['Real'].values day_pred = predictions[predictions.index.day == day[2]]['Predictions'].values daily_error.append(bm.mean_absolute_percentage_error(day_real, day_pred)) rush_real = rush_hour_predictions[rush_hour_predictions.index.day == day[2]]['Real'].values rush_pred = rush_hour_predictions[rush_hour_predictions.index.day == day[2]]['Predictions'].values rush_hour_error.append( bm.mean_absolute_percentage_error(rush_real, rush_pred)) from datetime import date daily_error = np.array(daily_error).transpose() rush_hour_errors = np.array(rush_hour_error).transpose() print(daily_error.shape) indexes = [date(day[0], day[1], day[2]).ctime() for day in days] data = {'Daily Error': daily_error, 'Rush Hour Error': rush_hour_error}
mapes = {} for file_name in FILES.keys(): time_interval = 20 data = bm.read_data(FILES[file_name]) data['Scaled'], sc = bm.scale_data(data) data.drop(['Speed'], axis='columns', inplace=True) data.replace(0, np.nan, inplace=True) reframed = bm.series_to_supervised(data, time_interval, 7 * 24 * 60, 5) reframed = reframed[reframed.index.month == 5] est = np.mean(reframed.values[:, :-1], axis=1) result = reframed.values[:, -1] mape = bm.mean_absolute_percentage_error(result, est) mapes[file_name] = mape mapes_20 = pd.DataFrame.from_dict(data=mapes, orient='index', columns=['mape_20']) mapes = {} for file_name in FILES.keys(): time_interval = 30 data = bm.read_data(FILES[file_name]) data['Scaled'], sc = bm.scale_data(data) data.drop(['Speed'], axis='columns', inplace=True) data.replace(0, np.nan, inplace=True)