2016-03-17 32 views
-2

假設我有兩個假設的時間序列數據,一個是降雨量,另一個是海洋表面溫度。使用Scikit或Pandas的兩個時間序列的關係

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也是確定兩個時間序列數據關係的好方法,但我還沒有在使用scikit或pandas的python中找到任何好的詳細示例。我更喜歡使用熵,但我不知道它是否可以回答問題2.我也想問一下在python中是否有一個排列分佈聚類,這似乎是解決問題1的有趣方法。感謝您的幫助!

+0

請說明您想使用哪種型號。否則,問題不清或太寬泛。 – Goyo

+0

@Goyo如果你有關於python中置換分佈聚類的想法,或者如果沒有想法,那真的會有所幫助,那麼熵將是一個不錯的選擇。 –

回答

3

剛剛繪製在一起散點圖中,你應該能夠告訴的關係:

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()