Implementation:Interpretml Interpret Construct Bins
| Field | Value |
|---|---|
| Sources | InterpretML |
| Domains | Data_Preprocessing, Interpretability |
| Last Updated | 2026-02-07 12:00 GMT |
Overview
Construct_Bins is a concrete tool for discretizing features into bins provided by the InterpretML library.
Description
The construct_bins function takes cleaned feature data and target values, then computes bin definitions (cut points for continuous features, category mappings for nominal features) using the specified binning strategy. It also returns bin weights, feature bounds, histogram data, and optional differential privacy noise scaling. This function supports multiple binning strategies including quantile-based, uniform, and humanized quantile binning, and can operate under differential privacy constraints when epsilon and delta parameters are provided.
Usage
Import this function when you need to convert continuous and categorical features into discrete bins for EBM training. This is the primary entry point for the binning pipeline.
Code Reference
Source Location
- Repository
interpretml/interpret- File
python/interpret-core/interpret/utils/_preprocessor.py- Lines
- 602--676
Signature
def construct_bins(
X,
y,
sample_weight,
feature_names_given,
feature_types_given,
max_bins_leveled,
binning="quantile",
min_samples_bin=1,
min_unique_continuous=0,
seed=None,
epsilon=None,
delta=None,
composition=None,
privacy_bounds=None,
):
Import
from interpret.utils._preprocessor import construct_bins
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
X |
array-like | Yes | Feature matrix |
y |
array-like | Yes | Target values |
sample_weight |
array-like | No | Per-sample weights |
feature_names_given |
list | Yes | Names for each feature column |
feature_types_given |
list | Yes | Types for each feature (e.g., "continuous", "nominal") |
max_bins_leveled |
list[int] | Yes | Maximum number of bins per interaction level |
binning |
str | No | Binning strategy: "quantile", "uniform", or "quantile_humanized" (default: "quantile") |
min_samples_bin |
int | No | Minimum samples per bin (default: 1) |
min_unique_continuous |
int | No | Minimum unique values for continuous treatment (default: 0) |
seed |
int | No | Random seed for reproducibility |
epsilon |
float | No | Differential privacy epsilon parameter |
delta |
float | No | Differential privacy delta parameter |
composition |
str | No | DP composition method |
privacy_bounds |
dict | No | Per-feature privacy bounds |
Outputs
Returns a tuple of:
| Index | Name | Type | Description |
|---|---|---|---|
| 0 | feature_names_in |
list | Validated feature names |
| 1 | feature_types_in |
list | Validated feature types |
| 2 | bins |
list | Bin definitions per feature |
| 3 | bin_weights |
list | Weight tensors per bin |
| 4 | feature_bounds |
list | Min/max bounds per feature |
| 5 | histogram_weights |
list | Histogram weight data |
| 6 | missing_val_counts |
list | Count of missing values per feature |
| 7 | unique_val_counts |
list | Count of unique values per feature |
| 8 | noise_scale |
float/None | DP noise scale (None if DP not used) |
Usage Examples
Basic Usage
from interpret.utils._preprocessor import construct_bins
import numpy as np
X = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0], [7.0, 8.0]])
y = np.array([0, 1, 0, 1])
result = construct_bins(
X, y,
sample_weight=None,
feature_names_given=["feature_0", "feature_1"],
feature_types_given=["continuous", "continuous"],
max_bins_leveled=[256],
binning="quantile",
)
feature_names_in, feature_types_in, bins, bin_weights, feature_bounds, histogram_weights, missing_val_counts, unique_val_counts, noise_scale = result
Related Pages
- Principle:Interpretml_Interpret_Feature_Binning_And_Discretization
- Environment:Interpretml_Interpret_Python_Core_Environment
- Environment:Interpretml_Interpret_Native_Libebm_Environment
- Heuristic:Interpretml_Interpret_EBM_Hyperparameter_Tuning_Guide
- Heuristic:Interpretml_Interpret_Memory_Budget_Heuristic
- Heuristic:Interpretml_Interpret_Categorical_Float_Conversion_Gotcha