Dekomposisi Deret Waktu untuk Deteksi Outlier

Deteksi Anomali dengan Python

Bekhruz (Bex) Tuychiev

Kaggle Master, Data Science Content Creator

Musiman

  • Pola berulang pada deret waktu
  • Frekuensi tetap:
    • per jam
    • harian
    • mingguan
    • bulanan, dll.
  • Contoh:
    • Suhu harian
    • Penjualan es krim
Deteksi Anomali dengan Python

Musiman

Line plot harga pembukaan saham Google.

Deteksi Anomali dengan Python

seasonal_decompose

from statsmodels.tsa.seasonal import seasonal_decompose

results = seasonal_decompose(google['Open'], period=365)

print(results)
<statsmodels.tsa.seasonal.DecomposeResult object at 0x7f0a67fac820>
Deteksi Anomali dengan Python

Memplot musiman

results.seasonal.plot(color="red", figsize=(12, 4))

Plot musiman harga pembukaan saham Google

Deteksi Anomali dengan Python

Contoh musiman

Contoh musiman pada deret waktu.

Deteksi Anomali dengan Python

Plot awal saham

Plot awal harga pembukaan saham Google

Deteksi Anomali dengan Python

Tren

results.trend.plot(color="red", figsize=(12, 4))

Deteksi Anomali dengan Python

Contoh tren

Contoh tren deret waktu.

Deteksi Anomali dengan Python

Residual

results.resid.plot(color="red", figsize=(12, 4))

Plot residual harga pembukaan saham Google.

Deteksi Anomali dengan Python

Dekomposisi

figure = results.plot()

figure.set_figwidth(12)
figure.set_figheight(8)

Tiga komponen deret waktu divisualisasikan.

Deteksi Anomali dengan Python

Melatih classifier

# Extract and reshape residuals
results = seasonal_decompose(google['Volume'], period=365)
residuals = results.resid
residuals = residuals.values.reshape(-1, 1)


# Fit MAD mad = MAD().fit(residuals)
# Find the outliers is_outlier = mad.labels_ == 1 outliers = google[is_outlier] print(len(outliers))
81
Deteksi Anomali dengan Python

Ayo berlatih!

Deteksi Anomali dengan Python

Preparing Video For Download...