-
Notifications
You must be signed in to change notification settings - Fork 112
Open
Labels
bugSomething isn't workingSomething isn't working
Milestone
Description
Hi,
first, thank you for maintaining this package -- I appreciate your work put into this :).
I found a bug in the OptimalBinning.binning_table.plot() method. If specifying add_special = False and show_bin_labels=True, the position of the plotted WoE value for category "Missing" is incorrect. See a reproducible example below:
from optbinning import OptimalBinning
from scipy.special import expit
import numpy as np
import pandas as pd
def main():
np.random.seed(42)
# 1) Generate continuous feature
N = 500
x1 = np.random.normal(loc=0, scale=1.5, size=N)
# 2) True logistic model parameters
beta0 = -0.5
beta1 = 2.0
# 3) Compute probabilities
p = expit(beta0 + beta1 * x1)
# 4) Generate binary target
y = np.random.binomial(1, p)
# 5) Insert missing values (to trigger the optbinning issue)
x1[::25] = np.nan # every 50th sample missing
X = pd.DataFrame({"x1": x1})
optb = OptimalBinning(
user_splits=[-1,0,1],
name="x1",
dtype="numerical",
solver="cp", # simplest deterministic solver
monotonic_trend=None, # or "ascending"/"descending"
)
optb.fit(X["x1"], y)
X_binned = optb.transform(X["x1"], metric="woe")
binning_table = optb.binning_table.build()
optb.binning_table.plot(
show_bin_labels=True, add_special=False, add_missing=True, metric="woe"
)
optb.binning_table.plot(
show_bin_labels=True, add_special=True, add_missing=True, metric="woe"
)
if __name__ == "__main__":
main()
If add_special = False:

If add_special = True:
Note that the WoE value for "Missing" is correct in the second case.
I will link a PR to this Issue.
guillermo-navas-palencia
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working