Outliers
polars_ts.outliers
Group-aware outlier detection and treatment for time series. Closes #61.
detect_outliers(df, target_col='y', method='zscore', id_col='unique_id', time_col='ds', threshold=3.0, window=None)
Detect outliers in a time series DataFrame.
Parameters
df
Input DataFrame.
target_col
Column to check for outliers.
method
Detection method: "zscore", "iqr", "hampel", or
"rolling_zscore".
id_col
Column identifying each time series.
time_col
Column with timestamps.
threshold
Sensitivity parameter. For zscore: number of std deviations
(default 3). For IQR: multiplier (default 1.5 when
threshold=1.5).
window
Rolling window size (required for "rolling_zscore" and
"hampel").
Returns
pl.DataFrame
Original DataFrame with boolean is_outlier column appended.
treat_outliers(df, target_col='y', method='zscore', replacement='clip', id_col='unique_id', time_col='ds', threshold=3.0, window=None)
Detect and replace outliers in a time series DataFrame.
Parameters
df
Input DataFrame.
target_col
Column to treat.
method
Detection method (same as :func:detect_outliers).
replacement
How to replace outliers: "clip" (winsorize), "median"
(group median), "interpolate" (linear), or "null".
id_col
Column identifying each time series.
time_col
Column with timestamps.
threshold
Detection threshold.
window
Rolling window size for rolling methods.
Returns
pl.DataFrame DataFrame with outliers replaced.