OptBinning is a Python library for optimal binning, a data preprocessing technique used in machine learning to transform continuous or categorical features into discrete bins. It supports various binning algorithms, including optimal, isotonic, and tree-based methods, and facilitates scorecard development. The current version is 0.21.0, with a release cadence of typically a new minor version every 1-2 months, often including new features and bug fixes.
pip install optbinningVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to use `OptimalBinning` to discretize both numerical and categorical features for a binary target. It covers initialization, fitting the binning process, and transforming the data, finally printing the generated binning tables.
Ensure `ortools` is installed with a version less than 9.12. If you encounter issues, try `pip install 'ortools<9.12'`.
Upgrade to OptBinning v0.21.0 or newer to use the `Scorecard.transform` method, or implement the transformation logic manually using `Scorecard.decision_function`.
Upgrade to OptBinning v0.19.0 or newer to ensure `pandas.DataFrame` indexes are preserved during transformation. If upgrading is not possible, explicitly manage index alignment after transformation.
Always refer to the official documentation for your specific OptBinning version when working with `sample_weight` to understand its support and proper usage in `OptimalBinning` and `Scorecard` classes.
Install the correct version of `ortools` by running `pip install 'ortools<9.12'` to satisfy OptBinning's dependency requirements.
Upgrade OptBinning to version 0.21.0 or newer (`pip install --upgrade optbinning`). Alternatively, use `Scorecard.decision_function` if you need the scores for a specific dataset.
Ensure that `binning_instance.fit(X, y)` or `binning_instance.fit_transform(X, y)` is called before attempting to call `binning_instance.transform(X)`.
Provide both the feature series/array (X) and the target series/array (y) to the `fit` method, e.g., `optimal_binning_instance.fit(X['feature_name'], y)`.