RJT1990 / pyflux

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

Error in arimax.plot_predict, plot_predict_is, predict? #100

Closed shr264 closed 7 years ago

shr264 commented 7 years ago

Hi,

I am getting the following error in trying to replicate the example on http://www.pyflux.com/docs/arimax.html: Traceback (most recent call last):

File "", line 28, in model.plot_predict(h=10, oos_data=data.iloc[-12:], past_values=100, figsize=(15,5))

File "/anaconda/envs/python3/lib/python3.6/site-packages/pyflux/arma/arimax.py", line 778, in plot_predict date_index = self.shift_dates(h)

File "/anaconda/envs/python3/lib/python3.6/site-packages/pyflux/tsm.py", line 537, in shift_dates if isinstance(date_index,pd.tseries.index.DatetimeIndex):

AttributeError: module 'pandas.tseries' has no attribute 'index'

Below is the code, which I have copied verbatim from the page:

import numpy as np import pandas as pd import pyflux as pf from datetime import datetime import matplotlib.pyplot as plt

data = pd.read_csv("https://vincentarelbundock.github.io/Rdatasets/csv/MASS/drivers.csv") data.index = data['time']; data.loc[(data['time']>=1983.05), 'seat_belt'] = 1; data.loc[(data['time']<1983.05), 'seat_belt'] = 0; data.loc[(data['time']>=1974.00), 'oil_crisis'] = 1; data.loc[(data['time']<1974.00), 'oil_crisis'] = 0; plt.figure(figsize=(15,5)); plt.plot(data.index,data['drivers']); plt.ylabel('Driver Deaths'); plt.title('Deaths of Car Drivers in Great Britain 1969-84'); plt.plot();

type(data['drivers'])

model = pf.ARIMAX(data=data, formula='drivers~1+seat_belt+oil_crisis', ar=1, ma=1, family=pf.Normal()) x = model.fit("MLE") x.summary()

model.plot_fit(figsize=(15,10))

model.plot_predict(h=10, oos_data=data.iloc[-12:], past_values=100, figsize=(15,5))

saitobay commented 7 years ago

@shr264 This troubles me too...... copy and paste,but failed at "predict" step. Anyone work through the examples? Many thanks.

RJT1990 commented 7 years ago

Likely a versioning issue (which version of pandas you are using).

RJT1990 commented 7 years ago

I'll see if I can push out an update that fixes this (along with some changes to the matplotlib library that affect functionality) in the near future, but unfortunately I cannot promise anything as I am very tied down with other work right now.

RJT1990 commented 7 years ago

Hey, I'm going to take a look at this today :)

RJT1990 commented 7 years ago

This is now fixed and is going to be in the release I am going to push in next 2 hours. Issue was a change in the pandas library modules for indexes. Now fixed, and will reflect this change in the version requirements.