Skip to content

Commit

Permalink
Merge pull request #81 from ing-bank/80-bucket_info
Browse files Browse the repository at this point in the history
80 bucket info
  • Loading branch information
orchardbirds authored Nov 24, 2021
2 parents 670525b + 10e43bb commit dc2f20f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

setup(
name="skorecard",
version="1.6.1",
version="1.6.2",
description="Tools for building scorecard models in python, with a sklearn-compatible API",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
14 changes: 10 additions & 4 deletions skorecard/reporting/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ def build_bucket_table(
stats["WoE"] = ((stats["% Non-event"] + epsilon) / (stats["% Event"] + epsilon)).apply(lambda x: np.log(x))
stats["IV"] = (stats["% Non-event"] - stats["% Event"]) * stats["WoE"]

stats["% Event"] = np.round(100 * stats["% Event"], 2)
stats["% Non-event"] = np.round(100 * stats["% Non-event"], 2)
stats["Event Rate"] = np.round(stats["Event Rate"], 3)

stats["WoE"] = np.round(stats["WoE"], 3)
stats["IV"] = np.round(stats["IV"], 3)

Expand All @@ -140,6 +144,8 @@ def build_bucket_table(
"Count (%)",
"Non-event",
"Event",
"% Event",
"% Non-event",
"Event Rate",
"WoE",
"IV",
Expand Down Expand Up @@ -167,10 +173,10 @@ def bucket_table(self, column):
the BucketingProcess ends up with the final buckets.
An example:
bucket | label | Count | Count (%) | Non-event | Event | Event Rate | WoE | IV
-----------|--------------------|-------|-----------|-----------|-------|------------|------|-----
0 | (-inf, 25000.0) | 479.0 | 7.98 | 300.0 | 179.0 | 37.37 | 0.73 | 0.05
1 | [25000.0, 45000.0) | 370.0 | 6.17 | 233.0 | 137.0 | 37.03 | 0.71 | 0.04
bucket | label | Count | Count (%) | Non-event | Event | % Event | % Non-event | Event Rate | WoE | IV
-------|--------------|-------|-----------|-----------|-------|---------|-------------|------------|------|-----
0 | (-inf, 25.0) | 61.0 | 1.36 | 57.0 | 4.0 | 0.41 | 1.62 | 0.066 |1.380 |0.017
1 | [25.0, 45.0) | 2024.0| 44.98 | 1536.0 | 488.0 | 49.64 |43.67 | 0.241 |-0.128|0.008
Args:
column: The column we wish to analyse
Expand Down
6 changes: 3 additions & 3 deletions tests/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_report_decision_tree(df):
tbt.transform(X)

df_out = build_bucket_table(X, y, column="LIMIT_BAL", bucketer=tbt)
assert df_out.shape == (5, 9)
assert df_out.shape == (5, 11)
# Make sure bucket table equals feature bucket mapping dict
assert (
dict(zip(df_out["bucket_id"].values, df_out["label"].values))
Expand All @@ -36,9 +36,9 @@ def test_report_decision_tree(df):
"Count (%)",
"Non-event",
"Event",
"% Event",
"% Non-event",
"Event Rate",
# "% Event",
# "% Non Event",
"WoE",
"IV",
]
Expand Down

0 comments on commit dc2f20f

Please sign in to comment.