Discretizer
class atom.data_cleaning.Discretizer(strategy="quantile", bins=5, labels=None, device="cpu", engine="sklearn", verbose=0, logger=None, random_state=None)[source]
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 train the estimators. Use any string
that follows the SYCL_DEVICE_FILTER filter selector,
e.g. engine: str, default="sklearn"device="gpu" to use the GPU. Read more in the
user guide.
Execution engine to use for the estimators. Refer to the
user guide for an explanation
regarding every choice. Choose from:
verbose: int, default=0
Verbosity level of the class. Choose from:
logger: str, Logger 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.array
Names of features seen during fit.
n_features_in_: int
Number of features seen during fit.
|
See Also
Perform encoding of categorical features.
Handle missing values in the data.
Transform the data to follow a Normal/Gaussian distribution.
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)
>>> print(atom["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
>>> 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 small
1 medium
2 medium
3 medium
4 small
...
564 large
565 small
566 large
567 small
568 small
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
>>> disc = Discretizer(
... strategy="custom",
... bins=[13, 18],
... labels=["small", "medium", "large"],
... verbose=2,
... )
>>> X["mean radius"] = disc.fit_transform(X[["mean radius"]])["mean radius"]
Fitting Discretizer...
Binning the features...
--> Discretizing feature mean radius in 3 bins.
>>> print(X["mean radius"])
0 small
1 medium
2 medium
3 medium
4 small
...
564 large
565 small
566 large
567 small
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_params | Get parameters for this estimator. |
inverse_transform | Does nothing. |
log | Print message and save to log file. |
save | Save the instance to a pickle file. |
set_params | Set the parameters of this estimator. |
transform | Bin the data into intervals. |
method fit(X, y=None)[source]
Fit to data.
method fit_transform(X=None, y=None, **fit_params)[source]
Fit to data, then transform it.
method get_params(deep=True)[source]
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.
|
method inverse_transform(X=None, y=None)[source]
Does nothing.
method log(msg, level=0, severity="info")[source]
Print message and save to log file.
method save(filename="auto", save_data=True)[source]
Save the instance to a pickle file.
Parameters | filename: str, default="auto"
Name of the file. Use "auto" for automatic naming.
save_data: bool, default=True
Whether to save the dataset with the instance. This
parameter is ignored if the method is not called from
atom. If False, remember to add the data to ATOMLoader
when loading the file.
|
method set_params(**params)[source]
Set the parameters of this estimator.
Parameters | **params : dict
Estimator parameters.
|
Returns | self : estimator instance
Estimator instance.
|
method transform(X, y=None)[source]
Bin the data into intervals.