Advanced monotonic binning, IV/WOE transformation, and random forest feature importance with parallel processing support
Project description
📊 Mono-Binning
Mono-Binning: Advanced Monotonic Binning with IV/WOE Transformation — Optimized for sParallel Execution, sFeature Selection, sModel Interpretability, and sRandom Forest Integration
Technical Topics:
- Monotonic Binning: Numeric and categorical binning with IV/WOE- monotonic trend enforcement via IsotonicRegression,Smart binning via qcut/cut,alpha smoothing
- Feature Engineering: Advanced smoothing and trend control.
- Parallel Processing: Multi-threaded IV/WOE calculation.
- Random Forest: Feature importance calculation.
- Missing Data Handling: Robust treatment for NaNs in binning.
🔧 Installation
pip install mono-binning
Features
✅ Monotonic & Categorical Binning
-
mono_bin() for numerical variables:
-
Smart binning via qcut/cut fallback.
-
Supports monotonic trend enforcement via IsotonicRegression.
-
Handles missing values with special WOE.
-
Applies alpha smoothing for stable IV/WOE.
-
char_bin() for categorical variables:
-
Treats 'nan', '', None, etc. as 'MISSING'.
-
Safe WOE calculation using smoothing. (bin_stats: pd.DataFrame, woe_map: Dict)
📚 Functions
| Feature | Description |
|---|---|
✅ mono_bin |
Monotonic binning for numerical features using quantile-based cutoffs, with smoothing and trend enforcement |
✅ char_bin |
Binning for categorical variables, treating missing or malformed entries as a distinct "MISSING" class |
| ✅ IV/WOE Output | All bin functions return bin stats and WOE maps |
| ✅ Missing Value Handling | Graceful support with separate WOE values for NaNs |
| ✅ Smoothing | Avoids instability with alpha smoothing |
| ✅ Trend Control | Use force_trend='i' for increasing or 'd' for decreasing trend via isotonic regression |
| ✅ Parallel Execution | Use calculate_iv_parallel() for multi-threaded performance |
| ✅ Random Forest | Built-in calculate_rf_importance() and its parallel counterpart help compare model-based vs IV-driven variable importance |
⚙️ Feature Highlights
| ✅ Feature | What You Did | Why It’s Smart |
|---|---|---|
| ✅ ThreadPoolExecutor | Parallel binning + RF importance | Speeds up large datasets |
| ✅ Alpha smoothing | Prevents divide-by-zero / log(0) issues | More robust WOE/IV calculations |
| ✅ NaN handling | Assigns special WOE bin to missing vals | Keeps mappings consistent and crash-free |
| ✅ Isotonic regression | Optional trend enforcement | Great for scorecard modeling |
| ✅ Execution toggle | Switch between concurrent & sequential | Flexible for local vs. production runs |
🚀 Quick Start & API Reference
🧪 1. calculate_iv() – Main IV/WOE Calculation
from mono_binning import calculate_iv
iv_summary, df_woe, woe_maps = calculate_iv(df, target='default_flag', execution='sequential', max_workers=4) # or 'concurrent'
🐢 2. calculate_iv_sequential() – Sequential IV Calculation
from mono_binning import calculate_iv_sequential
iv_summary, df_woe, woe_maps = calculate_iv_sequential(df, target='default_flag')
⚡ 3. calculate_iv_parallel() – ThreadPoolExecutor for concurrency IV Calculation
from mono_binning import calculate_iv_parallel
iv_summary, df_woe, woe_maps = calculate_iv_parallel(df, target='default_flag', max_workers=4)
🧱 4. mono_bin() – Numeric Monotonic Binning
from mono_binning import mono_bin
bin_stats, woe_map = mono_bin(df['default_flag'], df['loan_amt'], var_name='loan_amt')
🧵 6. _iv_worker() – Internal Helper for IV Processing.Wrapper to switch between sequential and concurrent modes (Used in Threading)
from mono_binning import _iv_worker
feature, bin_stats, woe_map = _iv_worker((df, 'default_flag', 'loan_amt', 0.5))
🌲 7. calculate_rf_importance() – Random Forest Feature Importance (numerical + categorical preprocessing).
from mono_binning import calculate_rf_importance.calculate_rf_importance_concurrent
importance_df = calculate_rf_importance(
df,
target='default_flag',
features=['loan_amt', 'income', 'education'])
importance_df = calculate_rf_importance_concurrent(
df,
target='default_flag',
features=['loan_amt', 'income', 'education'])
---
### **. `LICENSE** (MIT Example)**
```text
MIT License
Copyright (c) 2023 Anvesh Reddy minukuri
... (add full license text from https://choosealicense.com/licenses/mit/)
🚀 Deployment Steps
1. Build the Package
# Navigate to package root
cd mono-binning
# Install build tools
pip install build
# Create distribution
python -m build
This generates a dist/ folder with .whl and .tar.gz files.
2. Install Locally (Development)
pip install -e .
3. Run Tests
pip install pytest
pytest -v
4. Publish to PyPI
pip install twine
# TestPyPI (optional)
twine upload --repository testpypi dist/*
# Production PyPI
twine upload dist/*
|
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mono_binning-0.1.6.tar.gz.
File metadata
- Download URL: mono_binning-0.1.6.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
469b58aaad156c5b7f4e97ed71765e21af5f0caf7796c6bbb92037f3b7777943
|
|
| MD5 |
d686c993a23afedf787019cc2cec2b6d
|
|
| BLAKE2b-256 |
9a02f08af9cfbe8f56c342bad04235a94ce68056b5e88bd2d735cfa3fca06158
|
File details
Details for the file mono_binning-0.1.6-py3-none-any.whl.
File metadata
- Download URL: mono_binning-0.1.6-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2bc9831d37e1ec77b71a531e00a56c19422f0d5272fa3fde19c03eddf584bcd
|
|
| MD5 |
32b7f4ae3699fe73113c01c0b2aecde2
|
|
| BLAKE2b-256 |
ac3e863db03e87bb53e669c735ac74d6863302efc0540e4d729040588c6675e5
|