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()


            SUNACTIVITY
1700-12-31          5.0
1701-12-31         11.0
1702-12-31         16.0
1703-12-31         23.0
1704-12-31         36.0
1705-12-31         58.0
1706-12-31         29.0
1707-12-31         20.0
1708-12-31         10.0
1709-12-31          8.0
1710-12-31          3.0
1711-12-31          0.0
1712-12-31          0.0
1713-12-31          2.0
1714-12-31         11.0
1715-12-31         27.0
1716-12-31         47.0
1717-12-31         63.0
1718-12-31         60.0
1719-12-31         39.0
1720-12-31         28.0
1721-12-31         26.0
1722-12-31         22.0
1723-12-31         11.0
1724-12-31         21.0
1725-12-31         40.0
1726-12-31         78.0
1727-12-31        122.0
1728-12-31        103.0
1729-12-31         73.0
1730-12-31         47.0
1731-12-31         35.0
1732-12-31         11.0
1733-12-31          5.0
1734-12-31         16.0
1735-12-31         34.0
1736-12-31         70.0
1737-12-31         81.0
1738-12-31        111.0
1739-12-31        101.0
1740-12-31         73.0
1741-12-31         40.0
1742-12-31         20.0
1743-12-31         16.0
1744-12-31          5.0
1745-12-31         11.0
1746-12-31         22.0
1747-12-31         40.0
1748-12-31         60.0
1749-12-31         80.9
1750-12-31         83.4
1751-12-31         47.7
1752-12-31         47.8
1753-12-31         30.7
1754-12-31         12.2
1755-12-31          9.6
1756-12-31         10.2
1757-12-31         32.4
1758-12-31         47.6
1759-12-31         54.0
                    ...

[309 rows x 1 columns]
Out[45]:
<matplotlib.axes.AxesSubplot at 0x598e6d0>

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)


(2622.6363380680295, 2637.5697031756204, 2628.6067259132756)
(2619.403628696441, 2638.0703350809299, 2626.8666135029985)