CenterScaler transformer.
Mean centering (subtract mean from features).
Classes
Mean centering of categorical or numerical features.
Transforms features by subtracting the mean of each column, effectively resulting in a distribution centered at zero.
Constructor
__init__( self, columns: Optional[List[int]] = None, )
Theory
The centered value of a sample x is calculated as:
x_{centered} = x - \mu
where \mu is the mean of the training samples.
Parameters
columns
list of int
Indices of columns to transform. If
None, all columns are transformed.
Attributes
mean_
np.ndarray of shape (n_selected_columns,)
The per-column mean observed in the training data.
Center a simple 2D array:
python
>>> from tuiml.preprocessing.scaling import CenterScaler
>>> import numpy as np
>>> X = np.array([[1, 2], [3, 4], [5, 6]])
>>> center = CenterScaler()
>>> X_centered = center.fit_transform(X)
>>> print(np.round(X_centered.mean(axis=0), 2))
[0. 0.]
Methods
get_parameter_schema
(cls)
fit
(self, X: np.ndarray, y: Optional[np.ndarray]=None, feature_names: Optional[List[str]]=None) -> 'CenterScaler'
transform
(self, X: np.ndarray) -> np.ndarray
inverse_transform
(self, X: np.ndarray) -> np.ndarray
__repr__
(self) -> str