In [45]:
import numpy as np
from scipy import stats
import pandas as pd
import matplotlib.pyplot as plt
import statsmodels.api as sm
# print sm.datasets.sunspots.NOTE
sunspot_df = sm.datasets.sunspots.load_pandas().data
sunspot_df.plot()
# sunspot_df['YEAR'] = pd.to_datetime(sunspot_df['YEAR'], format='%Y')
# sunspot_df.index = pd.Index(sunspot_df['YEAR'])
sunspot_df.index = pd.Index(sm.tsa.datetools.dates_from_range('1700', '2008'))
del sunspot_df["YEAR"]
print(sunspot_df)
# print(sunspot_df.head())
sunspot_df.plot()
Out[45]:
In [37]:
fig = plt.figure(figsize=(12, 8))
ax1 = fig.add_subplot(211)
fig = sm.graphics.tsa.plot_acf(sunspot_df.values.squeeze(), lags=100, ax=ax1)
ax2 = fig.add_subplot(212)
fig = sm.graphics.tsa.plot_pacf(sunspot_df, lags=100, ax=ax2)
In [46]:
# sunspot_df['SUNACTIVITY'] = np.log(sunspot_df['SUNACTIVITY'])
# print(sunspot_df.values)
fig = plt.figure(figsize=(12, 8))
ax1 = fig.add_subplot(211)
fig = sm.graphics.tsa.plot_acf(sunspot_df.values.squeeze(), lags=100, ax=ax1)
ax2 = fig.add_subplot(212)
fig = sm.graphics.tsa.plot_pacf(sunspot_df, lags=100, ax=ax2)
In [51]:
arma_mod20 = sm.tsa.ARMA(sunspot_df, (2,0)).fit()
# print(arma_mod20.params)
arma_mod30 = sm.tsa.ARMA(sunspot_df, (3,0)).fit()
# print(arma_mod30.params)
print(arma_mod20.aic, arma_mod20.bic, arma_mod20.hqic)
print(arma_mod30.aic, arma_mod30.bic, arma_mod30.hqic)