kivi
Binning, WOE, IV and PSI for credit risk modeling
A pandas toolkit for scorecard development, variable screening and model monitoring:
fit bin edges once, see how well every bin separates good from bad, and catch population drift.
English · 简体中文
Documentation · Quickstart · User guide · API · Release notes
✨ Highlights
- 🏦 Built for risk teams. Covers the classing, screening and monitoring steps of credit scorecards and other risk models, with examples for special values, coarse classing and leakage checks.
- 📐 Fit once, reuse everywhere.
bin_edgeslearns quantile or uniform edges on a reference sample;chimerge_edges,tree_edgesandmonotonic_edgesalso use the target. The outer edges are infinite, so every future value still lands in a bin. - 🔍 Transparent results.
woe_tableandpsi_tablereturn raw counts, smoothed shares and a contribution per bin, not just one number. - 🧩 Nothing silently dropped. Missing values, special codes such as
-1and categories seen in only one sample get their own group. - 🧊 Honest smoothing. Empty cells are replaced by
smoothing(default 0.5) before normalizing, and the reported counts are never altered. - 🐼 Just pandas and NumPy. No Spark, no database drivers and no global random state in the core.
- 🌏 Bilingual, tested docs. Every example in the English and Chinese manuals runs in CI.
📊 Gallery
🧭 How it works
📦 Installation
pip install kivi
Requires Python 3.10+, NumPy 1.24+ and pandas 2.0+. For the latest development version, use pip install "git+https://github.com/gchensy/kivi".
Upgrading from 0.2.x? The API changed in 0.3. Read the migration guide before upgrading existing code.
🚀 Quickstart
import pandas as pd
from kivi.binning import bin_edges
from kivi.datasets import Dataset
from kivi.evaluate import psi_table
from kivi.woe import woe_table
data = Dataset.bank_data() # 4,521 bank marketing customers
reference, current = data.iloc[:3000], data.iloc[3000:]
edges = bin_edges(reference["age"], bins=5) # 1. fit once on the reference
before = pd.cut(reference["age"], edges) # 2. cut every sample
after = pd.cut(current["age"], edges)
evidence = woe_table(before, reference["target"]) # 3. measure
stability = psi_table(before, after)
print(evidence[["event", "non_event", "woe", "iv"]].round(3))
print(f"IV = {evidence['iv'].sum():.3f}, PSI = {stability['psi'].sum():.4f}")
event non_event woe iv
bin
(-inf, 32.0] 90 612 0.114 0.003
(32.0, 36.0] 55 475 -0.125 0.003
(36.0, 42.0] 58 529 -0.180 0.006
(42.0, 51.0] 71 569 -0.050 0.001
(51.0, inf] 74 467 0.189 0.007
IV = 0.019, PSI = 0.0024
Categorical columns skip the edges entirely:
jobs = woe_table(reference["job"], reference["target"])
print(f"IV(job) = {jobs['iv'].sum():.3f}") # IV(job) = 0.137
🧰 API at a glance
| Function | What it does |
|---|---|
kivi.binning.bin_edges |
Fit quantile or uniform edges on a reference sample, with infinite outer edges |
kivi.binning.cut |
Assign values to bins, with a separate group for each special value such as -1 |
kivi.binning.chimerge_edges |
Merge fine quantile bins with ChiMerge until neighbours differ significantly |
kivi.binning.tree_edges |
Decision-tree splits by entropy or Gini, with a minimum share per bin |
kivi.binning.monotonic_edges |
Merge fine quantile bins until the WOE is monotonic |
kivi.woe.woe_table |
Counts, shares, WOE and IV for every group |
kivi.evaluate.psi_table |
Per-group PSI contributions between two samples |
kivi.datasets.Dataset.bank_data |
The bundled bank marketing data |
📚 Documentation
| English | 中文 | |
|---|---|---|
| Quickstart | Read | 阅读 |
| Binning | Read | 阅读 |
| WOE and IV | Read | 阅读 |
| PSI | Read | 阅读 |
| Migrating from 0.2.x | Read | 阅读 |
🗺️ Roadmap
- ✅ Quantile and uniform binning, WOE, IV and PSI on a pandas core
- ✅ English and Simplified Chinese documentation with tested examples
- ✅ Special values such as
-1or-999in their own bins - ✅ Charted risk examples: special values, coarse classing, IV screening, PSI monitoring
- ✅ Supervised binning: ChiMerge, decision tree and monotonic WOE
- 🔜 Weighted counts
- 🔜 Scorecard workflow, validated against fixed reference samples
- 🔜 Spark and SQL as optional integrations
🤝 Contributing
git clone https://github.com/gchensy/kivi.git
cd kivi
python -m pip install -e '.[test,docs]'
python -m pytest # unit tests
python -m sphinx -W -b doctest docs docs/_build/doctest # documentation examples
python docs/build.py # English and Chinese HTML
After editing English pages or docstrings, run python docs/build.py --update-po and translate the new entries in docs/locale/zh_CN/LC_MESSAGES/kivi.po. See the development guide for details.
📄 License
The code is released under the MIT License. The bundled Bank Marketing data by S. Moro, P. Rita and P. Cortez (2014) is licensed under CC BY 4.0; see DATA-LICENSE.txt.
If kivi helps your models, a ⭐ helps others find it.
Metadata
Release files for kivi 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kivi-0.4.0.tar.gz | 180.6 kB | With provenance | Details for kivi-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kivi-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for kivi-0.4.0-py3-none-any.whl |
Total release size: 259.6 kB
Release files / kivi-0.4.0.tar.gz
| Download URL | kivi-0.4.0.tar.gz |
|---|---|
| Size | 180.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
288422b8dd9079852f9f77e53bf10d51c1b235503094c595067ad8b4754533cb
|
|
BLAKE2b-256 checksum How to use checksums |
509e3fec644baccc6475234686f7dc54fc6bf69e06fe99346f715e2fedc36f05
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logRelease files / kivi-0.4.0-py3-none-any.whl
| Download URL | kivi-0.4.0-py3-none-any.whl |
|---|---|
| Size | 79.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2cec2de94fd312a2650ea9cadf81b1a94bbc93acc24513c4b8830eeaececcd14
|
|
BLAKE2b-256 checksum How to use checksums |
dfc22fdac178f26da65b8cb58aab9f8c27a2812739d66531d62789fd9d6f3063
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logSecurity for kivi 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for kivi-0.4.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.