MDLDiscretizer transformer.
MDL (Minimum Description Length) based discretization.
Classes
Supervised discretization based on Minimum Description Length (MDL).
Finds optimal cut points by minimizing the class entropy, using the Fayyad & Irani's MDL criterion to determine when to stop splitting.
Constructor
__init__( self, min_instances: int = 10, columns: Optional[List[int]] = None, )
Overview
MDL discretization is a supervised method that uses the target labels to decide where to place bin boundaries. It typically performs better than unsupervised methods for classification tasks.
Theory
A cut point T for a feature A is chosen to minimize the class-weighted entropy. A split is accepted if the information gain satisfies:
Gain(A, T; S) > \frac{\log_2(n-1)}{n} + \frac{\Delta(A, T; S)}{n}
where n is the number of instances and \Delta is a penalty term based on the number of classes.
Parameters
min_instances
int
= 10
Minimum number of instances required in each bin.
columns
list of int
Indices of columns to discretize. If
None, all columns are processed.
Attributes
cut_points_
dict
Mapping of column index to the list of optimal cut points.
Discretize a feature using class labels:
python
>>> from tuiml.preprocessing.discretization import MDLDiscretizer
>>> import numpy as np
>>> X = np.array([[1], [2], [3], [4], [5], [6], [7], [8]])
>>> y = np.array([0, 0, 0, 0, 1, 1, 1, 1])
>>> discretizer = MDLDiscretizer()
>>> X_binned = discretizer.fit_transform(X, y)
Methods
get_parameter_schema
(cls)
fit
(self, X: np.ndarray, y: np.ndarray, feature_names: Optional[List[str]]=None) -> 'MDLDiscretizer'
transform
(self, X: np.ndarray) -> np.ndarray
cut_points_
(self)
__repr__
(self) -> str