季节性与趋势

用 Python 分析 IoT 数据

Matthias Voppichler

IT Developer

时间序列组成

  • 趋势
  • 季节性
  • 残差/噪声
series[t] = trend[t] + seasonal[t] + residual[t]
20.2 = 14.9 + 4.39 + 0.91
用 Python 分析 IoT 数据

季节性分解

import statsmodels.api as sm
# Run seasonal decompose
decomp = sm.tsa.seasonal_decompose(data["temperature"])
print(decomp.seasonal.head())

decomp.plot()
timestamp
2018-10-01 00:00:00   -3.670394
2018-10-01 01:00:00   -3.987451
2018-10-01 02:00:00   -4.372217
2018-10-01 03:00:00   -4.534066
2018-10-01 04:00:00   -4.802165
Freq: H, Name: temperature, dtype: float64
用 Python 分析 IoT 数据

季节性分解

季节性分解图

用 Python 分析 IoT 数据

组合图

# Plot the timeseries
plt.plot(data["temperature"], label="temperature")

decomp = sm.tsa.seasonal_decompose(data["temperature"]) # Plot trend and seasonality plt.plot(decomp.trend, label="trend") plt.plot(decomp.seasonal, label="seasonal") plt.show()
用 Python 分析 IoT 数据

组合图

季节性分解——组合图

用 Python 分析 IoT 数据

Passons à la pratique !

用 Python 分析 IoT 数据

Preparing Video For Download...