API Reference / base /

features.py

Base classes for feature engineering operations.

This module provides the foundation for feature selection, extraction, and construction methods.

Classes

FeatureMethod

class base.features.FeatureMethod(Registrable, ABC)

Abstract base class for all feature engineering operations.

Defines the standard workflow for discovering, extracting, or creating features from raw data. Concrete subclasses are registered with the component registry so they can be discovered by name.
Constructor
__init__(
    self,
)

Methods

__init__ (self)

Initialize feature method state.

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

Learn feature engineering 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 methods.
Returns
self
FeatureMethod
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 methods.
Returns
X_transformed
np.ndarray
Transformed data.
get_params (self) -> Dict[str, Any]

Return the method's public parameters.

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

Set method parameters.

Parameters
**params
dict
Parameter names mapped to new values. Each name must match an existing attribute.
Returns
self
FeatureMethod
The updated instance (for method chaining).
Raises
ValueError
If a parameter name does not match an existing attribute.
get_feature_names_out (self) -> Optional[List[str]]

Return output feature names after transformation.

Returns
feature_names_out
list of str or None
Names of the output features, or None if unavailable.

FeatureSelector

class base.features.FeatureSelector(FeatureMethod)

Base class for feature selection algorithms.

Feature selection identifies and preserves the most relevant subset of existing features based on statistical significance, model importance, or information theory.
Constructor
__init__(
    self,
    k: Optional[int] = None,
    threshold: Optional[float] = None,
)

Overview

Unlike extraction, selection does not create new features; it simplifies the model by pruning irrelevant or redundant inputs.

Parameters

k
int
The number of top-scoring features to retain.
threshold
float
The minimum score required for a feature to be selected.

Attributes

_selected_indices
np.ndarray
The indices of the features chosen during fit.
_feature_scores
np.ndarray
The raw scores calculated for each input feature.

Methods

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

Compute feature scores and select the feature subset.

Parameters
X
np.ndarray of shape (n_samples, n_features)
Training data.
y
np.ndarray of shape (n_samples,)
Target values. Required for feature selection.
Returns
self
FeatureSelector
The fitted instance (for method chaining).
Raises
ValueError
If y is None.
transform (self, X: np.ndarray) -> np.ndarray

Reduce data to the selected features.

Parameters
X
np.ndarray of shape (n_samples, n_features)
Data to transform.
Returns
X_transformed
np.ndarray of shape (n_samples, n_selected)
Data restricted to the selected feature columns.
get_selected_indices (self) -> np.ndarray

Return indices of the selected features.

Returns
indices
np.ndarray of shape (n_selected,)
Sorted indices of the features chosen during fit.
get_feature_scores (self) -> np.ndarray

Return the computed feature scores.

Returns
scores
np.ndarray of shape (n_features,)
Score for each input feature.
get_support (self, indices: bool=False) -> np.ndarray

Get a mask or indices of the selected features.

Parameters
indices
bool = False
If True, return the integer indices of the selected features; otherwise return a boolean mask over all features.
Returns
support
np.ndarray
Boolean mask of shape (n_features,), or integer indices of shape (n_selected,) if indices is True.

FeatureExtractor

class base.features.FeatureExtractor(FeatureMethod)

Base class for feature extraction and dimensionality reduction.

Feature extraction transforms the original high-dimensional data into a lower-dimensional representation while preserving as much information as possible (e.g., PCA, SVD).
Constructor
__init__(
    self,
    n_components: Optional[int] = None,
)

Parameters

n_components
int
The number of projection components or latent dimensions to extract.

Methods

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

Learn extraction parameters from data.

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

Extract features from data.

Parameters
X
np.ndarray of shape (n_samples, n_features)
Data to transform.
Returns
X_transformed
np.ndarray of shape (n_samples, n_components)
Extracted features.
inverse_transform (self, X: np.ndarray) -> np.ndarray

Reverse the transformation (if possible).

Parameters
X
np.ndarray of shape (n_samples, n_components)
Transformed data.
Returns
X_original
np.ndarray of shape (n_samples, n_features)
Reconstructed data in the original feature space.
Raises
NotImplementedError
If the extractor does not support inversion.

FeatureConstructor

class base.features.FeatureConstructor(FeatureMethod)

Base class for expanded feature construction.

Feature construction creates new features through combinations or non-linear expansions of existing inputs (e.g., Polynomial Interactions, Logarithmic mappings).
Constructor
__init__(
    self,
)

Methods

__init__ (self)

Initialize feature constructor.

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

Learn construction parameters from data.

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

Construct new features from data.

Parameters
X
np.ndarray of shape (n_samples, n_features)
Data to transform.
Returns
X_transformed
np.ndarray
Data augmented with the constructed features.

Functions

Func

feature_selector

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

Register a feature selector class with the component registry.

Parameters

name
str
Registration name. Defaults to the class name.
tags
list of str
Searchable tags describing the selector.
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 FeatureSelector component.
python
>>> from tuiml.base.features import feature_selector, FeatureSelector
>>> @feature_selector(tags=["statistical", "univariate"])
... class ChiSquaredSelector(FeatureSelector):
...     pass
Func

feature_extractor

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

Register a feature extractor class with the component registry.

Parameters

name
str
Registration name. Defaults to the class name.
tags
list of str
Searchable tags describing the extractor.
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 FeatureExtractor component.
python
>>> from tuiml.base.features import feature_extractor, FeatureExtractor
>>> @feature_extractor(tags=["dimensionality_reduction"])
... class PCAExtractor(FeatureExtractor):
...     pass
Func

feature_constructor

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

Register a feature constructor class with the component registry.

Parameters

name
str
Registration name. Defaults to the class name.
tags
list of str
Searchable tags describing the constructor.
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 FeatureConstructor component.
python
>>> from tuiml.base.features import feature_constructor, FeatureConstructor
>>> @feature_constructor(tags=["polynomial"])
... class PolynomialFeaturesGenerator(FeatureConstructor):
...     pass