【问题标题】:Relationship of two time series using Scikit or Pandas使用 Scikit 或 Pandas 的两个时间序列的关系
【发布时间】:2016-07-03 14:32:37
【问题描述】:

假设我有两个假设的时间序列数据,一个是降雨量,另一个是海洋表面温度。

Rainfall Time Series:
2001-12-31    25 mm
2002-12-31    50 mm
2003-12-31    75 mm
2004-12-31    50 mm
2005-12-31    25 mm
2006-12-31    10 mm
2007-12-31    6 mm
2008-12-31    8 mm
2009-12-31    10 mm
2010-12-31    12 mm
2011-12-31   20 mm
2012-12-31    75 mm

Rainfall Time Series:
2001-12-31   36 (Degrees Celsius)
2002-12-31   37 (Degrees Celsius)
2003-12-31   38 (Degrees Celsius)
2004-12-31   37 (Degrees Celsius)
2005-12-31   36 (Degrees Celsius)
2006-12-31   34 (Degrees Celsius)
2007-12-31   32 (Degrees Celsius)
2008-12-31   33 (Degrees Celsius)
2009-12-31   34 (Degrees Celsius)
2010-12-31   35 (Degrees Celsius)
2011-12-31   35.9 (Degrees Celsius)
2012-12-31    38 (Degrees Celsius)

我想回答这些问题:

1.) How are the two time series related?
2.) Is there a way to find out that if either one of time series changes the other one will also change? And if it does by how much?

我们知道降雨量和海洋表面温度是相关的,而不是虚假的(不像https://goo.gl/EcR3sO 中的航空公司乘客和大米生产的时间序列示例)我读过关于两个时间序列的近似熵和回归,我什至读到ARIMA 也是确定两个时间序列数据关系的好方法,但我还没有在 python 中使用 scikit 或 pandas 找到任何好的详细示例。我更喜欢用熵,但不知道能不能回答问题2。我也想问一下python中是否有排列分布聚类,这似乎是解决问题1的一个有趣的方法。谢谢你的帮助!

【问题讨论】:

  • 请说明您要使用的型号。否则问题不清楚或太宽泛。
  • @Goyo 如果您对 python 中的排列分布聚类有想法,或者如果没有,那么熵将是一个不错的选择。

标签: python pandas scikit-learn time-series


【解决方案1】:

只需将它们一起绘制在散点图中,您就应该能够分辨出关系:

1) 这两个系列有什么关系? (使用 UnivariateSpline 的示例,随意使用即可)

    x = 25,50,75,50,25,10,6,8,10,12,20,75
    y = 36,37,38,37,36,34,32,33,34,35,35.9,38

    import numpy as np
    from scipy import interpolate
    f = interpolate.UnivariateSpline(x, y)
    xo = np.linspace(min(x),max(x),1000)
    yo = f(xo)

    df = np.diff(yo) / np.diff(xo)
    print(df.shape,xo.shape)
    import matplotlib.pyplot as plt
    plt.scatter(x,y)
    plt.plot(xo,yo)
    plt.show()

2) 它是如何变化的?使用“拟合”到数据的函数的一阶导数。

    plt.plot(xo[:-1],df)
    plt.show() 

【讨论】:

    猜你喜欢
    • 2013-09-18
    • 2011-09-22
    • 1970-01-01
    • 1970-01-01
    • 2018-02-13
    • 2018-07-17
    • 2016-04-15
    • 1970-01-01
    相关资源
    最近更新 更多