KBinsDiscretizer<T>
Models & Types · AiDotNet.Preprocessing.Discretizers
Bins continuous features into discrete intervals.
Inheritance: TransformerBase<T, Matrix<T>, Matrix<T>> → KBinsDiscretizer<T>
For Beginners
This transformer groups continuous values into bins (categories):
- Uniform strategy: Divides the range into equal-width intervals
- Quantile strategy: Divides so each bin has roughly equal number of samples
Example with 3 bins using uniform strategy: [1, 5, 10, 15, 20, 25] with range 1-25 creates bins:
- Bin 0: 1-9 → values 1, 5
- Bin 1: 9-17 → values 10, 15
- Bin 2: 17-25 → values 20, 25
How It Works
KBinsDiscretizer discretizes features into k equal-width or quantile-based bins. This is useful for transforming continuous features into categorical features, which can help certain models like decision trees and reduce sensitivity to outliers.
Constructors
| Constructor | Summary |
|---|---|
KBinsDiscretizer(int nBins, BinningStrategy strategy, EncodeMode encode, int[] columnIndices) |
Creates a new instance of KBinsDiscretizer. |
Properties
| Property | Summary |
|---|---|
BinningStrategy Strategy { get; } |
Gets the binning strategy used. |
EncodeMode Encode { get; } |
Gets the encoding mode used. |
List<T[]> BinEdges { get; } |
Gets the bin edges for each feature computed during fitting. |
bool SupportsInverseTransform { get; } |
Gets whether this transformer supports inverse transformation. |
int NBins { get; } |
Gets the number of bins used for discretization. |
Methods
| Method | Summary |
|---|---|
string[] GetFeatureNamesOut(string[] inputFeatureNames) |
Gets the output feature names after transformation. |