Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions sklego/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,16 @@ def impl(estimator, X, y_true):
# fair so we return 0
if len(y_given_z1_y1) == 0:
warn(
f"No samples with y_hat == {positive_target} for {sensitive_column} == 1, returning 0",
f"No samples with y_true == {positive_target} and y_hat == {positive_target} "
f"for {sensitive_column} == 1, returning 0",
RuntimeWarning,
)
return 0

if len(y_given_z0_y1) == 0:
warn(
f"No samples with y_hat == {positive_target} for {sensitive_column} == 0, returning 0",
f"No samples with y_true == {positive_target} and y_hat == {positive_target} "
f"for {sensitive_column} == 0, returning 0",
RuntimeWarning,
)
return 0
Expand Down
1 change: 1 addition & 0 deletions tests/test_metrics/test_equal_opportunity.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@ def test_warning_is_logged(sensitive_classification_dataset):
# Trigger a warning.
equal_opportunity_score("x2", positive_target=2)(mod_fair, X, y)
assert issubclass(w[-1].category, RuntimeWarning)
assert "y_true == 2 and y_hat == 2" in str(w[-1].message)
Loading