【问题标题】:Seasonal ARIMA with Python, freq H not understood?使用 Python 的季节性 ARIMA,频率 H 不明白?
【发布时间】:2016-09-28 07:35:20
【问题描述】:

我是新来的。我正在尝试通过TIME SERIE DECOMPOSITION EXAMPLECSV 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

请尝试帮助我。

【问题讨论】:

    标签: python statistics time-series statsmodels


    【解决方案1】:

    查看了一些博客,并测试了一些解决方案。我带着这个来了:

    values 添加到 df.Close 允许像这样进行分解:

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

    【讨论】:

    • 是的,这是当前必需的。这将很快改变,以便使用明确指定的freq,而不是在这种情况下从熊猫系列的时间索引中获取它。
    猜你喜欢
    • 2018-08-24
    • 2023-03-24
    • 2019-03-29
    • 1970-01-01
    • 2016-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多