Seasonal decomposition
polars_ts.decomposition.seasonal_decomposition
seasonal_decomposition(df, freq, method='additive', id_col='unique_id', target_col='y', time_col='ds')
Perform seasonal decomposition of time series data using either an additive or multiplicative method.
Additive: Y(t) = T(t) + S(t) + E(t)
Multiplicative: Y(t) = T(t) * S(t) * E(t)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Polars DataFrame containing the time series data. |
required |
freq
|
int
|
The seasonal period (e.g., 12 for monthly data with yearly seasonality). |
required |
method
|
Literal['additive', 'multiplicative']
|
The decomposition method (additive or 'multiplicative'). |
'additive'
|
id_col
|
str
|
The column to group by (e.g., for multiple time series). |
'unique_id'
|
target_col
|
str
|
The column containing the time series values to decompose. |
'y'
|
time_col
|
str
|
The column containing the time values. |
'ds'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Polars DataFrame with the decomposed components: trend, seasonal component, and residuals. |