Base classes for preprocessing operations.
This module provides the foundation for all data preprocessing transformers.
Classes
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.See Also
Methods
fit
(self, X: np.ndarray, y: Optional[np.ndarray]=None) -> 'Preprocessor'
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).
fit_transform
(self, X: np.ndarray, y: Optional[np.ndarray]=None) -> np.ndarray
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.
set_params
(self, **params) -> 'Preprocessor'
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.
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
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_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.
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'
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).
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
(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_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
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
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