IQROutlierDetector transformer.

IQR-based outlier detection and handling.

Classes

IQROutlierDetector

class preprocessing.outliers.iqr.IQROutlierDetector(Transformer)

Detect and handle outliers using the Interquartile Range (IQR).

Identifies "extreme" values that fall far outside the central 50% of the data distribution.
Constructor
__init__(
    self,
    factor: float = 1.5,
    action: str = 'clip',
    columns: Optional[List[int]] = None,
)

Overview

The IQR method is a non-parametric outlier detection technique. It defines a "normal" range based on the distance between the first and third quartiles.

Theory

The Interquartile Range (IQR) is IQR = Q3 - Q1. A value x is considered an outlier if:

x < Q1 - k \cdot IQR \quad \text{or} \quad x > Q3 + k \cdot IQR

where k is the multiplier (typically 1.5).

Parameters

factor
float = 1.5

The multiplier :math:`k`.

  • 1.5: Detects "mild" outliers (Tukey's standard).
  • 3.0: Detects "extreme" outliers.
action
{"clip", "nan", "remove"} = "clip"

Strategy to handle detected outliers:

  • "clip": Replace outliers with the nearest boundary value.
  • "nan": Replace outliers with np.nan.
  • "remove": Delete rows containing outliers (use with caution in pipelines).
columns
list of int
Indices of columns to process. If None, all columns are checked.

Attributes

bounds_
dict
Mapping of column index to the calculated (lower, upper) boundaries.

Notes

Robustness:
  • Since it uses quartiles, this method is less sensitive to outliers than
mean/sigma-based methods.
  • It assumes a unimodal distribution but not necessarily normality.

Remove outliers from a distribution:

python
>>> from tuiml.preprocessing.outliers import IQROutlierDetector
>>> import numpy as np
>>> X = np.array([[10], [12], [11], [10.5], [100.0]])
>>> detector = IQROutlierDetector(action="clip")
>>> X_clean = detector.fit_transform(X)

Methods

get_parameter_schema (cls)
fit (self, X: np.ndarray, y: Optional[np.ndarray]=None, feature_names: Optional[List[str]]=None) -> 'IQROutlierDetector'
transform (self, X: np.ndarray) -> np.ndarray
bounds_ (self)
__repr__ (self) -> str