RJT1990 / pyflux

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

ARIMA models with non-zero integ parameter can't predict. #60

Open smartsystems4u opened 7 years ago

smartsystems4u commented 7 years ago

When creating an ARIMA models with non-zero integ parameter causes PyFlux to not generate information on latent variables and causes predict(), plot_predict() and plot_z() methods to fail.

This is using PyFlux version 0.4.0.

Here's the code to reproduce the issue:

import numpy as np
import pandas as pd
import pyflux as pf
from datetime import datetime
import matplotlib.pyplot as plt
get_ipython().magic(u'matplotlib inline')

data = pd.read_csv('https://vincentarelbundock.github.io/Rdatasets/csv/datasets/sunspot.year.csv')
data.index = data['time'].values

plt.figure(figsize=(15,5))
plt.plot(data.index,data['sunspot.year'])
plt.ylabel('Sunspots')
plt.title('Yearly Sunspot Data');

model = pf.ARIMA(data=data,ar=4,ma=4,integ=10,target='sunspot.year')

model.plot_z(indices=range(1,9))

model.plot_predict(h=20,past_values=50,figsize=(15,5))

and the traceback for plot_z():

--------------------------------------------------------------------------- ValueError Traceback (most recent call last) in () ----> 1 model.plot_z(indices=range(1,9)) /Users/willem/dev/ml/keras/mlpy/lib/python2.7/site-packages/pyflux/tsm.pyc in plot_z(self, indices, figsize, **kwargs) 531 Pretty plot 532 """ --> 533 self.latent_variables.plot_z(indices=indices,figsize=figsize,**kwargs) 534 535 def plot_parameters(self,indices=None,figsize=(15,5),**kwargs): /Users/willem/dev/ml/keras/mlpy/lib/python2.7/site-packages/pyflux/latent_variables.pyc in plot_z(self, indices, figsize, loc) 229 230 else: --> 231 raise ValueError("No information on latent variable to plot!") 232 233 plt.xlabel('Value') ValueError: No information on latent variable to plot!


And the traceback for plot_predict():

--------------------------------------------------------------------------- Exception Traceback (most recent call last) in () ----> 1 model.plot_predict(h=20,past_values=50,figsize=(15,5)) /Users/willem/dev/ml/keras/mlpy/lib/python2.7/site-packages/pyflux/arma/arma.pyc in plot_predict(self, h, past_values, intervals, **kwargs) 326 327 if self.latent_variables.estimated is False: --> 328 raise Exception("No latent variables estimated!") 329 else: 330 # Retrieve data, dates and (transformed) latent variables Exception: No latent variables estimated!
RJT1990 commented 7 years ago

Thanks for reporting the issue. I'll look to get this fixed for the upcoming release. Strange because I thought tests covered that, but will have a look

TolganLight commented 6 years ago

This issue is still occurring. Has it been rectified? On version pyflux‑0.4.15‑cp27‑cp27m‑win_amd64

PoetCoderJun commented 6 years ago

modify to:

model = pf.ARIMA(data=data,ar=4,ma=4,integ=10,target='sunspot.year')
model.fit()
model.plot_z(indices=range(1,9))

and then it work