使用没有 DatetimeIndex 但频率已知的 statsmodels.seasonal_decompose() [英] Using statsmodels.seasonal_decompose() without DatetimeIndex but with Known Frequency

查看:55
本文介绍了使用没有 DatetimeIndex 但频率已知的 statsmodels.seasonal_decompose()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个时间序列信号,我想在 Python 中分解,所以我求助于 statsmodels.seasonal_decompose().我的数据频率为 48(半小时).我遇到了与 this questioner 相同的错误,其中解决方案是从 Int 索引更改为 DatetimeIndex.但我不知道我的数据来自的实际日期/时间.

I have a time-series signal I would like to decompose in Python, so I turned to statsmodels.seasonal_decompose(). My data has frequency of 48 (half-hourly). I was getting the same error as this questioner, where the solution was to change from an Int index to a DatetimeIndex. But I don't know the actual dates/times my data is from.

这个 github 线程中,statsmodels 的一位贡献者说

In this github thread, one of the statsmodels contributors says that

"在 0.8 中,您应该能够将 freq 指定为关键字参数覆盖索引."

"In 0.8, you should be able to specify freq as keyword argument to override the index."

但对我来说似乎并非如此.这是说明我的问题的最小代码示例:

But this seems not to be the case for me. Here is a minimal code example illustrating my issue:

import statsmodels.api as sm
dta = pd.Series([x%3 for x in range(100)])
decomposed = sm.tsa.seasonal_decompose(dta, freq=3)

AttributeError: 'RangeIndex' object has no attribute 'inferred_freq'

版本信息:

import statsmodels
print(statsmodels.__version__)
0.8.0

有没有办法在 statsmodels 中分解具有指定频率但没有 DatetimeIndex 的时间序列?

Is there a way to decompose a time-series in statsmodels with a specified frequency but without a DatetimeIndex?

如果没有,是否有在 Python 中执行此操作的首选替代方案?我查看了 Seasonal 包,但 它的 github 列出了 0 次下载/月、1 个贡献者和最后一次提交 9几个月前,所以我不确定我的项目是否要依赖它.

If not, is there a preferred alternative for doing this in Python? I checked out the Seasonal package, but its github lists 0 downloads/month, one contributor, and last commit 9 months ago, so I'm not sure I want to rely on that for my project.

推荐答案

感谢 josef-pkt 在 github 上回答这个问题.statsmodels 0.8.0 中存在一个错误,如果传递 Pandas 对象,它总是尝试根据 DatetimeIndex 计算推断频率.

Thanks to josef-pkt for answering this on github. There is a bug in statsmodels 0.8.0 where it always attempts to calculate an inferred frequency based on a DatetimeIndex, if passed a Pandas object.

使用 Pandas 系列时的解决方法是将它们在 numpy 数组中的值传递给 seasonal_decompose().例如:

The workaround when using Pandas series is to pass their values in a numpy array to seasonal_decompose(). For example:

import statsmodels.api as sm

my_pandas_series = pd.Series([x%3 for x in range(100)])
decomposed = sm.tsa.seasonal_decompose(my_pandas_series.values, freq=3)

(没有错误)

这篇关于使用没有 DatetimeIndex 但频率已知的 statsmodels.seasonal_decompose()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆