OutlierPercentileHandler¶
yohou.preprocessing.outlier.OutlierPercentileHandler
¶
Bases: BaseTransformer
Handle outliers based on percentile thresholds.
Values outside the specified percentile range are either clipped to the percentile values or set to NaN. Percentiles are computed during fit.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
low
|
float or None
|
Lower percentile (0-100). Values below this percentile are handled. If None, no lower bound is applied. |
None
|
high
|
float or None
|
Upper percentile (0-100). Values above this percentile are handled. If None, no upper bound is applied. |
None
|
strategy
|
(clip, nan)
|
How to handle outliers: - "clip": Replace outliers with percentile values - "nan": Replace outliers with NaN |
"clip"
|
Attributes¶
| Name | Type | Description |
|---|---|---|
thresholds_ |
dict
|
Dictionary mapping column names to (low_value, high_value) tuples. |
Examples¶
>>> import polars as pl
>>> from datetime import datetime, timedelta
>>> import numpy as np
>>> from yohou.preprocessing import OutlierPercentileHandler
>>> np.random.seed(42)
>>> X = pl.DataFrame({
... "time": [datetime(2020, 1, 1) + timedelta(days=i) for i in range(100)],
... "value": np.random.randn(100).tolist(),
... })
>>> # Clip to 5th-95th percentile
>>> handler = OutlierPercentileHandler(low=5, high=95)
>>> handler.fit(X)
OutlierPercentileHandler(high=95, low=5)
>>> X_handled = handler.transform(X)
>>> "time" in X_handled.columns
True
>>> # IQR-based outlier detection (clip to 25th-75th percentile)
>>> handler = OutlierPercentileHandler(low=25, high=75)
>>> handler.fit(X)
OutlierPercentileHandler(...)
>>> X_handled = handler.transform(X)
>>> len(X_handled)
100
See Also¶
OutlierThresholdHandler: Handle outliers based on fixed thresholds.
Source Code¶
Show/Hide source
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
Methods¶
get_feature_names_out(input_features=None)
¶
Get output feature names for transformation.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
input_features
|
list of str or None
|
Column names of the input features. If |
None
|
Returns¶
| Type | Description |
|---|---|
list of str
|
Output feature names after transformation. |
Source Code¶
Show/Hide source
Tutorials¶
The following example notebooks use this component:
-
How to Clean Time Series Data
Data-Features
End-to-end data cleaning pipeline combining SimpleTimeImputer and SeasonalImputer for missing values with OutlierThresholdHandler for anomaly clipping.
-
How to Handle Outliers in a Forecasting Pipeline
Data-Features
Detect and clip outliers with OutlierThresholdHandler and OutlierPercentileHandler, then see how outliers affect conformal prediction intervals.