time series forecasting help #122056
Unanswered
gozzdec
asked this question in
Programming Help
Replies: 1 comment
-
I can see that your MAPE and RMSE function calculate the mean absolute percentage error and root mean squared error considering all horizons of the prediction (h=12) at one. I have a similar function that calculates it by horizon in case you're interested. I think it would be more accurate to follow these formulas for RMSFE: I'm also quite concerned about the huge % errors and rmse. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello.Can you please help? I have limited coding skills and i have to be sure my codes are correct or not?I have time series dataset as below. I want to forecast nex year quantity monthly basis,so 2024. Also, I want to use statforecast library. However,My mape and rmse result is high
p1.xlsx
Date Quantity 2020-01-31 5190 2020-02-28 5110 2020-03-31 7154 2020-04-30 2644 2020-05-31 6482 2020-06-30 12223 2020-07-31 11535 2020-08-31 10250 2020-09-30 13831 2020-10-31 13831 2020-11-30 6162 2020-12-31 13448 2021-01-31 5040 2021-02-28 9699 2021-03-31 11562 2021-04-30 5196 2021-05-31 6358 2021-06-30 3189 2021-07-31 2795 2021-08-31 3300 2021-09-30 599 2021-10-31 4090 2021-11-30 9965 2021-12-31 3935 2022-01-31 559 2022-02-28 400 2022-03-31 1959 2022-04-30 4430 2022-05-31 5833 2022-06-30 8113 2022-07-31 400 2022-08-31 6283 2022-09-30 3640 2022-10-31 400 2022-11-30 2795 2022-12-31 13831 2023-01-31 4025 2023-02-28 1994 2023-03-31 792 2023-04-30 1154 2023-05-31 497 2023-06-30 2344 2023-07-31 2239 2023-08-31 2800 2023-09-30 4492 2023-10-31 4534 2023-11-30 4386 2023-12-31 502
And my python codes as below.
p1.reset_index(inplace=True)
p1 = p1[[‘Date’, ‘Quantity’]]
p1[‘unique_id’] = “1”
p1.columns = [‘ds’, ‘y’ ,‘unique_id’] train_p1 = p1[p1.ds <= ‘2022-12-31’]
test_p1 = p1[p1.ds >= ‘2023-01-31’]
models_p1 = [
AutoARIMA(),
AutoETS(),
Naive(),
] # Period we are predicting forward
horizon = len(test_p1) # 12
sf_p1 = StatsForecast(
df=train_p1,
models=models_p1,
freq=‘M’,
n_jobs=-1
)
p1_preds = sf_p1.forecast(horizon)
p1_preds = p1_preds.merge(test_p1, how=‘inner’, on=[‘unique_id’, ‘ds’])
plot_p1 = pd.concat([train_p1, p1_preds]).set_index(‘ds’)
fig, ax = plt.subplots(1, 1, figsize = (12, 4))
plot_p1[[‘y’, ‘AutoARIMA’, ‘AutoETS’ ]].plot(ax=ax, linewidth=2)
ax.set_title('(p1) ', fontsize=10)
ax.set_ylabel(‘Quantity’, fontsize=10)
ax.set_xlabel(‘Date’, fontsize=10)
ax.legend(prop={‘size’: 10})
ax.grid()
def MAPE(true, preds):
absolute_percentage_errors = np.abs((true - preds) / true)
absolute_percentage_errors[np.isnan(absolute_percentage_errors)] = 0
mape = np.mean(absolute_percentage_errors) * 100
return mape
m_autoarima= MAPE(p1_preds[‘y’], p1_preds[‘AutoARIMA’])
m_autoets= MAPE(p1_preds[‘y’], p1_preds[‘AutoETS’])
m_naive= MAPE(p1_preds[‘y’], p1_preds[‘Naive’])
print(‘MAPE and RMSE result for p1’)
print(f"MAPE for AutoARIMA: {m_autoarima:.2f}%“)
print(f"MAPE for AutoETS: {m_autoets:.2f}%”)
print(f"MAPE for Naive: {m_naive:.2f}%")
def RMSE(true, preds):
squared_errors = (true - preds) ** 2
rmse = np.sqrt(np.mean(squared_errors))
return rmse
rm_autoarima= RMSE(p1_preds[‘y’], p1_preds[‘AutoARIMA’])
rm_autoets= RMSE(p1_preds[‘y’], p1_preds[‘AutoETS’])
rm_naive= RMSE(p1_preds[‘y’], p1_preds[‘Naive’])
print(f"RMSE for AutoARIMA: {rm_autoarima:.2f}“)
print(f"RMSE for AutoETS: {rm_autoets:.2f}”)
print(f"RMSE for Naive: {rm_naive:.2f}")
MAPE for AutoARIMA: 314.98%
MAPE for AutoETS: 382.85%
MAPE for Naive: 912.52%
RMSE for AutoARIMA: 3626.45
RMSE for AutoETS: 4382.10
RMSE for Naive: 11450.33
forecasting for 2024
sf_p1_f = StatsForecast(
models=models_p1,
freq=‘M’
)
sf_p1_f.fit(p1)
forecast_p1 = sf_p1_f.predict(h=12, level=[95])
Beta Was this translation helpful? Give feedback.
All reactions