pyflux icon indicating copy to clipboard operation
pyflux copied to clipboard

Wrong dates when doing prediction with ARMA model

Open GuillaumeLeclerc opened this issue 9 years ago • 6 comments

Hello,

I was trying out the library and fit a simple ARMA(4, 4) model. I tried running predictions and it seems the dates of the output are completely wrong.

In [51]: model.predict(1)
Out[51]: 
                       training
2025-01-26 09:00:00  230.533628

In [52]: model.predict(2)
Out[52]: 
                       training
2034-12-05 08:00:00  230.533628
2034-12-05 09:00:00  227.872326

In [53]: model.predict(3)
Out[53]: 
                       training
2044-10-13 07:00:00  230.533628
2044-10-13 08:00:00  227.872326
2044-10-13 09:00:00  228.856676

Is is a known bug or I did something wrong ?

GuillaumeLeclerc avatar Apr 18 '17 15:04 GuillaumeLeclerc

Taking a look at this today!

RJT1990 avatar Jun 16 '17 08:06 RJT1990

Is this issue not fixed? It still seems to be an open bug....:)

satishreddy-m avatar Apr 01 '18 09:04 satishreddy-m

how to fix this issue ? it seems that pro has not been solved, as now it's still backward prediction when using model.predict()

addiehxg avatar May 11 '18 03:05 addiehxg

Hi, any news on this one?

giobruner avatar Sep 04 '18 14:09 giobruner

I believe I found where the bug lies. The method shift_dates of the TSM class is currently not working with pandas datetime index. The code on line 541

(date_index[len(date_index)-1] - date_index[len(date_index)-2]).seconds

will always return the number of seconds in the timedelta object (by documentation >= 0 and < 1 day), not the number of total seconds between the dates. To fix it just simply use:

date_index += pd.DateOffset(seconds=(date_index[len(date_index)-1] - date_index[len(date_index)-2]).total_seconds())

ryshoooo avatar Feb 05 '19 06:02 ryshoooo

@ryshoooo 's solution is spot on and worked for me. Only thing is that we have to change the code from line 538: if pd.infer_freq(date_index) in ['H', 'M', 'S',]: to if pd.infer_freq(date_index)[-1] in ['H', 'M', 'S','T']:

zhongjie526 avatar Nov 05 '19 10:11 zhongjie526