Skip to content

Commit

Permalink
fix metric_missing=0 is ignored in Scorecard._fit guillermo-navas-pal…
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpanmj committed Dec 18, 2022
1 parent d20ed46 commit ab7b940
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion optbinning/scorecard/scorecard.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ def _fit(self, X, y, sample_weight, metric_special, metric_missing,

binning_table.loc[
nt-1-n_specials:nt-2, "Points"] = metric_special * c
elif metric_missing != 'empirical':
if metric_missing != 'empirical':
binning_table.loc[nt-1, "Points"] = metric_missing * c

binning_table.index.names = ['Bin id']
Expand Down
24 changes: 24 additions & 0 deletions tests/test_scorecard.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,27 @@ def test_verbose():
with open("tests/results/test_scorecard_verbose.txt", "w") as f:
with redirect_stdout(f):
scorecard.fit(X, y)


def test_missing_metrics():
n = 100
data = pd.DataFrame(
{'target': np.hstack(
(np.random.choice([0, 1], n, p=[0.1, 0.9]),
np.random.choice([0, 1], n, p=[0.9, 0.1])
)
),
'var': [np.nan] * n+['A'] * n}
)

binning_process = BinningProcess(['var'])
scaling_method_params = {'min': 0, 'max': 100}

scorecard = Scorecard(
binning_process=binning_process,
estimator=LogisticRegression(),
scaling_method="min_max",
scaling_method_params=scaling_method_params
).fit(data, data.target)

assert scorecard.table()['Points'].iloc[-1] == 0

0 comments on commit ab7b940

Please sign in to comment.