時系列データの季節性・トレンド・ノイズ

Pythonで学ぶ時系列データの可視化

Thomas Vincent

Head of Data Science, Getty Images

時系列の特性

時系列の特性

Pythonで学ぶ時系列データの可視化

時系列の特性

  • 季節性:データに明確な周期的パターンがあるか?
  • トレンド:データが一貫した上昇または下降傾向を示しているか?
  • ノイズ:他のデータと一致しない外れ値や欠損値があるか?
Pythonで学ぶ時系列データの可視化

時系列の分解

import statsmodels.api as sm
import matplotlib.pyplot as plt
from pylab import rcParams

rcParams['figure.figsize'] = 11, 9
decomposition = sm.tsa.seasonal_decompose(
                co2_levels['co2'])
fig = decomposition.plot()

plt.show()
Pythonで学ぶ時系列データの可視化

CO2データの時系列分解プロット

時系列の分解

Pythonで学ぶ時系列データの可視化

時系列分解からの成分抽出

print(dir(decomposition))
['__class__', '__delattr__', '__dict__',
 ... 'plot', 'resid', 'seasonal', 'trend']
print(decomposition.seasonal)
datestamp
1958-03-29    1.028042
1958-04-05    1.235242
1958-04-12    1.412344
1958-04-19    1.701186
Pythonで学ぶ時系列データの可視化

時系列の季節性成分

decomp_seasonal = decomposition.seasonal

ax = decomp_seasonal.plot(figsize=(14, 2))
ax.set_xlabel('Date')
ax.set_ylabel('Seasonality of time series')
ax.set_title('Seasonal values of the time series')

plt.show()
Pythonで学ぶ時系列データの可視化

時系列の季節性成分

時系列の季節性

Pythonで学ぶ時系列データの可視化

時系列のトレンド成分

decomp_trend = decomposition.trend

ax = decomp_trend.plot(figsize=(14, 2))
ax.set_xlabel('Date')
ax.set_ylabel('Trend of time series')
ax.set_title('Trend values of the time series')

plt.show()
Pythonで学ぶ時系列データの可視化

時系列のトレンド成分

時系列のトレンド

Pythonで学ぶ時系列データの可視化

時系列のノイズ成分

decomp_resid = decomp.resid

ax = decomp_resid.plot(figsize=(14, 2))
ax.set_xlabel('Date')
ax.set_ylabel('Residual of time series')
ax.set_title('Residual values of the time series')

plt.show()
Pythonで学ぶ時系列データの可視化

時系列のノイズ成分

時系列のノイズ

Pythonで学ぶ時系列データの可視化

練習しましょう!

Pythonで学ぶ時系列データの可視化

Preparing Video For Download...