API Reference / base /

preprocessing.py

Base classes for preprocessing operations.

This module provides the foundation for all data preprocessing transformers.

Classes

Preprocessor

class base.preprocessing.Preprocessor(Registrable, ABC)

Abstract base class for all data preprocessing operations.

Defines a consistent API for fitting parameters to training data and applying those parameters to transform data.
Constructor
__init__(
    self,
)

Overview

Preprocessors are the building blocks of data pipelines. They can be unsupervised (only X) or supervised (X and y).

Notes

Subclasses must implement fit and transform.

Methods

__init__ (self)

Initialize preprocessor state.

get_parameter_schema (cls) -> Dict[str, Dict[str, Any]]

Return JSON Schema for constructor parameters.

fit (self, X: np.ndarray, y: Optional[np.ndarray]=None) -> 'Preprocessor'

Learn preprocessing parameters from data.

Parameters
X
np.ndarray of shape (n_samples, n_features)
Training data.
y
np.ndarray of shape (n_samples,)
Target values. Required only by supervised preprocessors.
Returns
self
Preprocessor
The fitted instance (for method chaining).
transform (self, X: np.ndarray) -> np.ndarray

Apply the learned transformation to data.

Parameters
X
np.ndarray of shape (n_samples, n_features)
Data to transform.
Returns
X_transformed
np.ndarray
Transformed data.
fit_transform (self, X: np.ndarray, y: Optional[np.ndarray]=None) -> np.ndarray

Fit to data, then transform it in one step.

Parameters
X
np.ndarray of shape (n_samples, n_features)
Training data.
y
np.ndarray of shape (n_samples,)
Target values. Required only by supervised preprocessors.
Returns
X_transformed
np.ndarray
Transformed data.
get_params (self) -> dict

Return the preprocessor's public parameters.

Returns
params
dict
Mapping of parameter names to their current values.
set_params (self, **params) -> 'Preprocessor'

Set transformation parameters.

Parameters
**params
dict
Parameter names mapped to new values. Each name must match an existing attribute.
Returns
self
Preprocessor
The updated instance (for method chaining).
Raises
ValueError
If a parameter name does not match an existing attribute.

Transformer

class base.preprocessing.Transformer(Preprocessor)

Base class for feature transformers.

Transformers apply mathematical operations to change the scale, distribution, or representation of feature values.

Attributes

_n_features_in
int
Number of input features expected by the transformer.
_feature_names_in
list of str
The names of the features seen during fit.

Methods

inverse_transform (self, X: np.ndarray) -> np.ndarray

Reverse the transformation (if possible).

Parameters
X
np.ndarray of shape (n_samples, n_features)
Transformed data.
Returns
X_original
np.ndarray
Data mapped back to the original scale/space.
Raises
NotImplementedError
If the transformer does not support inversion.
get_feature_names_out (self, input_features: Optional[List[str]]=None) -> List[str]

Get output feature names.

Parameters
input_features
list of str
Input feature names. If given, they are returned as-is; otherwise names seen during fit (or generated x0, x1, ... placeholders) are used.
Returns
feature_names_out
list of str
Output feature names.

SupervisedTransformer

class base.preprocessing.SupervisedTransformer(Transformer)

Base class for supervised feature transformers.

Unlike standard transformers, supervised transformers utilize the target labels (y) during the fit process to optimize the transformation (e.g., Target Encoding, Decision-Tree Binning).

Methods

fit (self, X: np.ndarray, y: np.ndarray) -> 'SupervisedTransformer'

Learn transformation parameters from data and targets.

Parameters
X
np.ndarray of shape (n_samples, n_features)
Input data.
y
np.ndarray of shape (n_samples,)
Target values (required).
Returns
self
SupervisedTransformer
The fitted instance (for method chaining).

ResamplingTransformer

class base.preprocessing.ResamplingTransformer(Preprocessor)

Base class for instance-level transformations.

Specialized preprocessors that can change the row count of a dataset, such as resampling algorithms or extreme outlier removers.

Methods

transform (self, X: np.ndarray, y: Optional[np.ndarray]=None) -> tuple

Transform instances, possibly changing the number of rows.

Parameters
X
np.ndarray of shape (n_samples, n_features)
Input data.
y
np.ndarray of shape (n_samples,)
Target values.
Returns
X_transformed
np.ndarray
Transformed data (row count may differ from the input).
y_transformed
np.ndarray or None
Correspondingly transformed target values.
fit_transform (self, X: np.ndarray, y: Optional[np.ndarray]=None) -> tuple

Fit to data, then transform it in one step.

Parameters
X
np.ndarray of shape (n_samples, n_features)
Input data.
y
np.ndarray of shape (n_samples,)
Target values.
Returns
X_transformed
np.ndarray
Transformed data (row count may differ from the input).
y_transformed
np.ndarray or None
Correspondingly transformed target values.

Functions

Func

preprocessor

Line 311
preprocessor(name: Optional[str]=None, tags: Optional[List[str]]=None, version: str='1.0.0', author: Optional[str]=None)

Register a preprocessor class with the component registry.

Parameters

name
str
Registration name. Defaults to the class name.
tags
list of str
Searchable tags describing the preprocessor.
version
str = "1.0.0"
Component version string.
author
str
Component author.

Returns

decorator
callable
Class decorator that registers the decorated class in the registry as a Preprocessor component.
python
>>> from tuiml.base.preprocessing import preprocessor, Transformer
>>> @preprocessor(tags=["normalization"])
... class MinMaxScaler(Transformer):
...     pass
Func

transformer

Line 352
transformer(name: Optional[str]=None, tags: Optional[List[str]]=None, version: str='1.0.0', author: Optional[str]=None)

Register a transformer class with the component registry.

Parameters

name
str
Registration name. Defaults to the class name.
tags
list of str
Searchable tags describing the transformer.
version
str = "1.0.0"
Component version string.
author
str
Component author.

Returns

decorator
callable
Class decorator that registers the decorated class in the registry as a Transformer component.
python
>>> from tuiml.base.preprocessing import transformer, Transformer
>>> @transformer(tags=["scaling", "normalization"])
... class StandardScaler(Transformer):
...     pass