RJT1990 / pyflux

Open source time series library for Python
BSD 3-Clause "New" or "Revised" License
2.1k stars 240 forks source link

Wrong dates when doing prediction with ARMA model #95

Open GuillaumeLeclerc opened 7 years ago

GuillaumeLeclerc commented 7 years ago

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 ?

RJT1990 commented 7 years ago

Taking a look at this today!

satishreddy-m commented 6 years ago

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

addiehxg commented 6 years ago

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

giobruner commented 5 years ago

Hi, any news on this one?

ryshoooo commented 5 years ago

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())
zhongjie526 commented 4 years ago

@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']: