季节性ARIMA与Python,freq H不明白?

时间:2016-05-30 12:55:11

标签: python statistics time-series statsmodels

我是新来的。我正在尝试使用此TIME SERIE DECOMPOSITION EXAMPLE跟踪此CSV DATA来分解时间系列。

我的问题出在从 statsmodels.tsa.seasonal 导入的 season_decompose 函数中。 我试图弄清楚如何将它应用于我的数据而没有任何成功。 这是我的代码:

import os
import csv
import time
import datetime
import pandas as pd
import numpy as np
import statsmodels.api as sm

from datetime import datetime
from datetime import timedelta, date
from dateutil.relativedelta import relativedelta
from statsmodels.tsa.seasonal import seasonal_decompose

import matplotlib.pyplot as plt
import matplotlib.dates as mdates

from itertools import product

df = pd.read_csv('table.csv', index_col=0)
df.index.name=None
df.reset_index(inplace=True)

start = datetime.strptime("2015-10-10", "%Y-%m-%d")
date_list = [start + relativedelta(days =x , hour=y) for x,y in product(range(0,93), range(0,24))]

df['index'] =date_list
df.set_index(['index'], inplace=True)
df.index.name=None
df.columns= ['Close']
df['Close'] = df.Close.apply(lambda x: int(x))
df.Close.plot(figsize=(12,8), title= 'Monthly Closehip', fontsize=14)


decomposition = seasonal_decompose(df.Close, freq=93)  

fig = decomposition.plot()  
fig.set_size_inches(15, 8)
plt.show()

我收到以下错误:

Traceback (most recent call last):
File "test.py", line 59, in <module>
    decomposition = seasonal_decompose(df.Close, freq=93)  
  File "/usr/local/lib/python2.7/dist-packages/statsmodels/tsa/seasonal.py", line 70, in seasonal_decompose
    pfreq = freq_to_period(pfreq)
  File "/usr/local/lib/python2.7/dist-packages/statsmodels/tsa/tsatools.py", line 657, in freq_to_period
    "think this in error.".format(freq))
ValueError: freq H not understood. Please report if you think this in error.

数据是csv文件:https://docs.google.com/a/esi.dz/spreadsheets/d/1s2Ak6Rqgm43FV4G_J_giWeHyi38xdZCBCz2v34k7iuA/edit?usp=sharing

请尝试帮助我。

1 个答案:

答案 0 :(得分:5)

查看一些博客后,测试一些解决方案。我来这个:

添加到df.Close允许进行如下分解:

decomposition = seasonal_decompose(df.Close.values, freq=168)