Created
May 15, 2022 14:59
-
-
Save h3ik0th/ad45ee6539193a9141a84e881359d99f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# retrieve forecast series for chosen quantiles, | |
# inverse-transform each series, | |
# insert them as columns in a new dataframe dfY | |
q50_RMSE = np.inf | |
q50_MAPE = np.inf | |
ts_q50 = None | |
pd.options.display.float_format = '{:,.2f}'.format | |
dfY = pd.DataFrame() | |
dfY["Actual"] = TimeSeries.pd_series(ts_test) | |
# helper function: get forecast values for selected quantile q and insert them in dataframe dfY | |
def predQ(ts_t, q): | |
ts_tq = ts_t.quantile_timeseries(q) | |
ts_q = scalerP.inverse_transform(ts_tq) | |
s = TimeSeries.pd_series(ts_q) | |
header = "Q" + format(int(q*100), "02d") | |
dfY[header] = s | |
if q==0.5: | |
ts_q50 = ts_q | |
q50_RMSE = rmse(ts_q50, ts_test) | |
q50_MAPE = mape(ts_q50, ts_test) | |
print("RMSE:", f'{q50_RMSE:.2f}') | |
print("MAPE:", f'{q50_MAPE:.2f}') | |
# call helper function predQ, once for every quantile | |
_ = [predQ(ts_tpred, q) for q in QUANTILES] | |
# move Q50 column to the left of the Actual column | |
col = dfY.pop("Q50") | |
dfY.insert(1, col.name, col) | |
dfY.iloc[np.r_[0:2, -2:0]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment