JoaquinAmatRodrigo / skforecast

Time series forecasting with machine learning models
https://skforecast.org
BSD 3-Clause "New" or "Revised" License
992 stars 113 forks source link

Miscalculated residuals in plot_residuals() #701

Closed schoulten closed 2 weeks ago

schoulten commented 3 weeks ago

The source code in plot_residuals() calculate the residuals as follows:

https://github.com/JoaquinAmatRodrigo/skforecast/blob/310915dc5b07b82acd731f43ab0f6b776ba5c6fd/skforecast/plot/plot.py#L59

But according to Rob Hyndman's book (FPP3), the correct calculation should be:

$$e{T+h} = y{T+h} - \hat{y}_{T+h|T}$$

Where $y{T+h}$ are the "Ground truth (correct) values" and $\hat{y}{T+h|T}$ are the "Values of predictions"

So, the above code should change to:

residuals = y_true - y_pred
JoaquinAmatRodrigo commented 3 weeks ago

You are right, thanks for reporting!

JoaquinAmatRodrigo commented 2 weeks ago

Fixed in https://github.com/JoaquinAmatRodrigo/skforecast/pull/702