Discretizer
Bin continuous data into intervals.
For each feature, the bin edges are computed during fit and, together with the number of bins, they define the intervals. Ignores categorical columns.
This class can be accessed from atom through the discretize method. Read more in the user guide.
Tip
The transformation returns categorical columns. Use the Encoder class to convert them back to numerical types.
Parameters |
strategy: str, default="quantile"
Strategy used to define the widths of the bins. Choose from:
bins: int, sequence or dict, default=5
Bin number or bin edges in which to split every column.
labels: sequence, dict or None, default=None
Label names with which to replace the binned intervals.
device: str, default="cpu"
Device on which to run the estimators. Use any string that
follows the SYCL_DEVICE_FILTER filter selector, e.g.
engine: str or None, default=Nonedevice="gpu" to use the GPU. Read more in the
user guide.
Execution engine to use for estimators.
If None, the default value is used. Choose from:
verbose: int, default=0
Verbosity level of the class. Choose from:
random_state: int or None, default=None
Seed used by the random number generator. If None, the random
number generator is the RandomState used by np.random . Only
for strategy="quantile".
|
Attributes |
feature_names_in_: np.ndarray
Names of features seen during
n_features_in_: intfit .
Number of features seen during fit .
|
See Also
Example
>>> from atom import ATOMClassifier
>>> from sklearn.datasets import load_breast_cancer
>>> X, y = load_breast_cancer(return_X_y=True, as_frame=True)
>>> atom = ATOMClassifier(X, y, random_state=1)
>>> print(atom["mean radius"])
0 13.48
1 18.31
2 17.93
3 15.13
4 8.95
...
564 14.34
565 13.17
566 17.30
567 17.68
568 14.80
Name: mean radius, Length: 569, dtype: float64
>>> atom.discretize(
... strategy="custom",
... bins=[13, 18],
... labels=["small", "medium", "large"],
... verbose=2,
... columns="mean radius",
... )
Fitting Discretizer...
Binning the features...
--> Discretizing feature mean radius in 3 bins.
>>> print(atom["mean radius"])
0 medium
1 large
2 medium
3 medium
4 small
...
564 medium
565 medium
566 medium
567 medium
568 medium
Name: mean radius, Length: 569, dtype: category
Categories (3, object): ['small' < 'medium' < 'large']
>>> from atom.data_cleaning import Discretizer
>>> from sklearn.datasets import load_breast_cancer
>>> X, y = load_breast_cancer(return_X_y=True, as_frame=True)
>>> print(X["mean radius"])
0 17.99
1 20.57
2 19.69
3 11.42
4 20.29
...
564 21.56
565 20.13
566 16.60
567 20.60
568 7.76
Name: mean radius, Length: 569, dtype: float64
>>> discretizer = Discretizer(
... strategy="custom",
... bins={"mean radius": [13, 18]},
... labels=["small", "medium", "large"],
... verbose=2,
... )
>>> X = discretizer.fit_transform(X)
Fitting Discretizer...
Binning the features...
--> Discretizing feature mean radius in 3 bins.
>>> print(X["mean radius"])
0 medium
1 large
2 large
3 small
4 large
...
564 large
565 large
566 medium
567 large
568 small
Name: mean radius, Length: 569, dtype: category
Categories (3, object): ['small' < 'medium' < 'large']
Methods
fit | Fit to data. |
fit_transform | Fit to data, then transform it. |
get_feature_names_out | Get output feature names for transformation. |
get_params | Get parameters for this estimator. |
inverse_transform | Do nothing. |
set_output | Set output container. |
set_params | Set the parameters of this estimator. |
transform | Bin the data into intervals. |
Fit to data.
Fit to data, then transform it.
Get output feature names for transformation.
Get parameters for this estimator.
Parameters |
deep : bool, default=True
If True, will return the parameters for this estimator and
contained subobjects that are estimators.
|
Returns |
params : dict
Parameter names mapped to their values.
|
Do nothing.
Returns the input unchanged. Implemented for continuity of the API.
Set output container.
See sklearn's user guide on how to use the
set_output
API. See here a description
of the choices.
Set the parameters of this estimator.
Parameters |
**params : dict
Estimator parameters.
|
Returns |
self : estimator instance
Estimator instance.
|
Bin the data into intervals.