Skip to content

Commit

Permalink
Merge pull request #227 from peterpanmj/miss_cat
Browse files Browse the repository at this point in the history
fix metric_missing=0 is ignored in Scorecard._fit #226
  • Loading branch information
guillermo-navas-palencia committed Jan 15, 2023
2 parents 9b145f6 + 289f524 commit fde1fe8
Show file tree
Hide file tree
Showing 2 changed files with 24 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 @@ -605,7 +605,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
23 changes: 23 additions & 0 deletions tests/test_scorecard.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,26 @@ 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():
data = pd.DataFrame(
{'target': np.hstack(
(np.tile(np.array([0, 1]), 50),
np.array([0]*90 + [1]*10)
)
),
'var': [np.nan] * 100 + ['A'] * 100}
)

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] == approx(0, rel=1e-6)

0 comments on commit fde1fe8

Please sign in to comment.