2014-11-24 118 views
3

我使用pandas.DataFrame.resample將隨機事件重新採樣到1小時的間隔,並且看到非常隨機的結果,如果我將間隔增加到2或4小時,結果似乎不會消失。這讓我懷疑Pandas是否有任何類型的方法來生成平滑密度內核,如帶有可調整帶寬的高斯核密度方法來控制平滑。我在文檔中沒有看到任何內容,但是我認爲在張貼在開發人員列表服務器上之前,我會在這裏發帖,因爲這是他們的偏好。 Scikit-Learn有precisely the Gaussian kernel density function that I want,所以我會盡量利用它,但這對熊貓來說是一個很棒的補充。pandas.DataFrame.resample的高斯核密度平滑?

任何幫助,非常感謝!

hourly[0][344:468].plot() 

enter image description here

回答

2

我現在已經找到了,這是選項在pandas.stats.moments.ewma和它的作品相當不錯。下面是結果:

from pandas.stats.moments import ewma 

hourly[0][344:468].plot(style='b') 
ewma(hourly[0][344:468], span=35).plot(style='k') 

enter image description here

+2

指數加權移動平均是實時(僅向後看)濾波器,並且是不一樣的高斯核,這是假想時間(期待和落後)。 – kb0 2017-05-18 20:09:26

3

大熊貓擁有一個滾動窗口申請一個聚集的能力。​​參數控制窗口的形狀。可以設置參數center,以便將標籤設置在窗口的中心而不是右邊緣。做高斯平滑:

hrly = pd.Series(hourly[0][344:468]) 
smooth = hrly.rolling(window=5, win_type='gaussian', center=True).mean(std=0.5) 

http://pandas.pydata.org/pandas-docs/stable/computation.html#rolling