Mean binarizer
fyt.core.processing.mean_binarizer
¶
MeanBinarizer
¶
Bases: BaseEstimator, TransformerMixin
Discretizes numerical features based on their mean values.
This transformer binarizes each feature by comparing values to the mean
computed during fitting. Values above the mean are encoded as 1, values
at or below the mean as 0. The per-feature means are stored on the fitted
instance as mean_ (ndarray of shape (n_features,)).
Examples:
>>> import numpy as np
>>> from fyt.core.processing.mean_binarizer import MeanBinarizer
>>> X = np.array([[1, 2], [3, 4], [5, 6]])
>>> binarizer = MeanBinarizer()
>>> binarizer.fit(X)
>>> binarizer.transform(X)
array([[0, 0],
[0, 0],
[1, 1]])
fit(X, y=None)
¶
Compute the mean for each feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame | ndarray
|
array-like or DataFrame of shape (n_samples, n_features) Training data. |
required |
y
|
object
|
Ignored. Present for sklearn compatibility. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
self |
'MeanBinarizer'
|
Returns the instance itself. |
set_output(*, transform=None)
¶
Set output configuration for compatibility with sklearn pipelines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transform
|
str | None
|
Output format for transform method. Not used in this wrapper. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
MeanBinarizer |
'MeanBinarizer'
|
The transformer itself. |
transform(X)
¶
Transform features to binary values based on the fitted mean.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame | ndarray
|
array-like or DataFrame of shape (n_samples, n_features) Data to transform. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
X_transformed |
ndarray or DataFrame of shape (n_samples, n_features) Binarized data. Values > mean are 1, values <= mean are 0. Returns pl.DataFrame if input was pl.DataFrame, otherwise ndarray. |