From 382c3b50ed31eb9af9d1a9f96d6915a2ab94a135 Mon Sep 17 00:00:00 2001 From: Matt Dancho Date: Wed, 4 Oct 2023 10:47:14 -0400 Subject: [PATCH] #46 start working on anomalize --- CHANGELOG.md | 5 +++++ src/pytimetk/core/anomaly.py | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/pytimetk/core/anomaly.py diff --git a/CHANGELOG.md b/CHANGELOG.md index c991bf4a..ca57189e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## pytimetk version 0.1.0.9000 (in development) +New Functions: + +- `augment_expanding()` +- `get_frequency()` + ## pytimetk version 0.1.0 (2023-10-02) Initial release. This release includes the following features: diff --git a/src/pytimetk/core/anomaly.py b/src/pytimetk/core/anomaly.py new file mode 100644 index 00000000..3c2e6a62 --- /dev/null +++ b/src/pytimetk/core/anomaly.py @@ -0,0 +1,26 @@ +import pandas as pd + +from pytimetk import ts_summary + +from statsmodels.tsa.seasonal import STL + +def stl_decompose(data, date_column, value_column, freq, trend, **kwargs): + + summary_df = ts_summary(data, date_column) + + # Decompose the time series + stl = STL(data[value_column], freq=freq, **kwargs) + res = stl.fit() + + # Build the dataframe containing the decomposed components + df = pd.DataFrame({ + 'date': data[date_column], + 'value': data[value_column], + 'trend': res.trend, + 'seasonal': res.seasonal, + 'residual': res.resid + }) + + return df + + \ No newline at end of file