EqualWidthDiscretizer transformer.
Equal-width binning for continuous features.
Classes
class preprocessing.discretization.equal_width.EqualWidthDiscretizer(Transformer)
Discretize continuous features into equal-width bins.
Partition consecutive values of numerical features into a set of bins of identical width.
Constructor
__init__( self, n_bins: int = 10, columns: Optional[List[int]] = None, )
Overview
Equal-width discretization divides the range of a feature into N intervals of the same size. This can help in reducing the influence of outliers (once binned) and simplifying complex continuous relationships.
Theory
The width w of each bin for a feature with range [x_{min}, x_{max}] is:
w = rac{x_{max} - x_{min}}{N}
Parameters
n_bins
int
= 10
Number of bins to create.
columns
list of int
Indices of columns to discretize. If
None, all columns are processed.
Attributes
bin_edges_
dict
Mapping of column index to the calculated bin edges.
Discretize values from 1 to 10 into 5 bins:
python
>>> from tuiml.preprocessing.discretization import EqualWidthDiscretizer
>>> import numpy as np
>>> X = np.array([[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]])
>>> discretizer = EqualWidthDiscretizer(n_bins=5)
>>> X_binned = discretizer.fit_transform(X)
>>> print(X_binned.flatten())
[0. 0. 1. 1. 2. 2. 3. 3. 4. 4.]
Methods
get_parameter_schema
(cls)
fit
(self, X: np.ndarray, y: Optional[np.ndarray]=None, feature_names: Optional[List[str]]=None) -> 'EqualWidthDiscretizer'
transform
(self, X: np.ndarray) -> np.ndarray
bin_edges_
(self)
__repr__
(self) -> str