ValueClipper transformer.

ValueClipper values to a specified range.

Classes

ValueClipper

class preprocessing.outliers.clip.ValueClipper(Transformer)

Clip feature values to a specified range or percentile.

Constrains the numerical range of features by capping values at the specified lower and upper thresholds.
Constructor
__init__(
    self,
    lower: Optional[float] = None,
    upper: Optional[float] = None,
    percentile: Optional[tuple] = None,
    columns: Optional[List[int]] = None,
)

Parameters

lower
float
Fixed lower bound. Values below this are set to lower.
upper
float
Fixed upper bound. Values above this are set to upper.
percentile
tuple of float
Percentile boundaries expressed as (lower_pct, upper_pct). If provided, the absolute bounds are calculated from the training data (e.g., (1, 99) for winsorization).
columns
list of int
Indices of columns to clip. If None, all columns are processed.

Attributes

bounds_
dict
Calculated (lower, upper) boundaries used for each column.

Clip values to the [0, 10] range:

python
>>> from tuiml.preprocessing.outliers import ValueClipper
>>> import numpy as np
>>> X = np.array([[-10], [5], [20]])
>>> clipper = ValueClipper(lower=0, upper=10)
>>> X_clipped = clipper.fit_transform(X)
>>> print(X_clipped.flatten())
[ 0.  5. 10.]

Methods

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