Python中时间序列的时间分解 [英] Temporal Disaggregation of Time Series in Python

查看:61
本文介绍了Python中时间序列的时间分解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一个能够对时间序列进行时间分解的包.R 中有一个名为 tempdisagg 的包.

I am trying to find a package that enables temporal disaggregation of timeseries. There is a package in R called tempdisagg.

https://journal.r-project.org/archive/2013/RJ-2013-028/RJ-2013-028.pdf

有人知道python中有没有类似的包?

Is there any similar package in python anyone is aware of?

如果python中不存在这个包,是否有一个可用的例子,有人可以将那个包中的这些函数从R调用到Python中.

If this package does not exist in python, is there an available example whereby someone may call such functions in that package from R into Python.

推荐答案

我创建了一个名为 timedisagg 基于 R tempdisagg 包.该包实现了基本的 Chow-Lin 和 Litterman 方法.它还允许基本的平均值、总和、第一次和最后一次转换选择,如 R 包.

I've created an open source Python package called timedisagg that is based on the R tempdisagg package. The package implements the basic Chow-Lin and Litterman methods. It also allows for basic average, sum, first and last conversion choices like the R package.

假设在 R 中调用以下函数将 sales.a 分解为 exports.q 的函数:

Given the following function call in R to disaggregate sales.a as a function of exports.q:

model <- td(sales.a ~ 0 + exports.q,method="chow-lin-maxlog",conversion="sum")

可以使用 timedisagg 进行类似的调用,如下所示:

A similar call can be made using timedisagg as below:

from timedisagg.td import TempDisagg
td_obj = TempDisagg(conversion="sum", method="chow-lin-maxlog")
final_disaggregated_output = td_obj(expected_dataset)

其中 expected_dataset 是具有以下格式的 Pandas 数据帧:

where the expected_dataset is a pandas dataframe with the following format:

      index  grain            X            y
0     1972      1   1432.63900          NaN
1     1972      2   1456.89100          NaN
2     1972      3   1342.56200          NaN
3     1972      4   1539.39400          NaN
4     1973      1   1535.75400          NaN
5     1973      2   1578.45800          NaN
6     1973      3   1574.72400          NaN
7     1973      4   1652.17100          NaN
8     1974      1   2047.83400          NaN
9     1974      2   2117.97100          NaN
10    1974      3   1925.92600          NaN
11    1974      4   1798.19000          NaN
12    1975      1   1818.81700   136.702329
13    1975      2   1808.22500   136.702329
14    1975      3   1649.20600   136.702329
15    1975      4   1799.66500   136.702329
16    1976      1   1985.75300   151.056074
17    1976      2   2064.66300   151.056074
18    1976      3   1856.38700   151.056074
19    1976      4   1919.08700   151.056074
..     ...    ...          ...          ...
152   2010      1  19915.79514   988.309676
153   2010      2  19482.48000   988.309676
154   2010      3  18484.64900   988.309676
155   2010      4  18026.46869   988.309676
156   2011      1  19687.52100          NaN
157   2011      2  18913.06608          NaN

这里的 X 是 exports.q,y 是 sales.a.

Here X is is exports.q and y is sales.a.

输出 final_disaggregated_output 将显示如下,其中 y_hat 是分解的销售额:

The output final_disaggregated_output will appear as below where y_hat is the disaggregated sales:

   index  grain         X   y      y_hat
0   1972      1  1432.639 NaN  21.656879
1   1972      2  1456.891 NaN  22.219737
2   1972      3  1342.562 NaN  20.855413
3   1972      4  1539.394 NaN  23.937916
4   1973      1  1535.754 NaN  24.229008

编辑 - 如果有人需要帮助将他们的数据处理到我的包中,请随时在 git 用于包.

Edit - If someone needs help working their data into my package, feel free to raise an issue at the git for the package.

这篇关于Python中时间序列的时间分解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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