Skip to content

Commit 2bc8115

Browse files
mattbitrabah-khalek
authored andcommitted
Fix wrong descriptions of performance issues
1 parent 55e527a commit 2bc8115

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

python-client/giskard/scanner/performance/performance_bias_detector.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,7 @@ def _detect_for_metric(
212212

213213
if is_issue:
214214
level = IssueLevel.MAJOR if abs(relative_delta) > 2 * self.threshold else IssueLevel.MEDIUM
215-
desc = (
216-
"For records in your dataset where {slicing_fn}, the recall is 96.8% lower than the global recall."
217-
)
215+
desc = "For records in your dataset where {slicing_fn}, the {metric} is {abs_deviation_perc}% {comparison_op} than the global {metric}."
218216

219217
issue = Issue(
220218
model=model,
@@ -229,6 +227,9 @@ def _detect_for_metric(
229227
"slice_metric": slice_metric,
230228
"reference_metric": ref_metric,
231229
"deviation": f"{relative_delta*100:+.2f}% than global",
230+
"deviation_perc": round(relative_delta * 100, 2),
231+
"abs_deviation_perc": round(abs(relative_delta) * 100, 2),
232+
"comparison_op": "lower" if metric.greater_is_better else "greater",
232233
"slice_size": len(sliced_dataset),
233234
"threshold": self.threshold,
234235
"p_value": p_value,

python-client/tests/scan/test_performance_bias_detector.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import logging
2+
from unittest import mock
3+
24
import numpy as np
35
import pandas as pd
46
import pytest
5-
from unittest import mock
67

78
from giskard import Dataset
89
from giskard.scanner.issues import Issue
@@ -58,6 +59,16 @@ def test_performance_bias_detector_with_tabular(german_credit_model, german_cred
5859
assert len(issues) > 0
5960
assert all([isinstance(issue, Issue) for issue in issues])
6061

62+
# Check that descriptions are coherent
63+
assert (
64+
issues[0].description
65+
== 'For records in your dataset where `purpose` == "business", the Precision is 5.33% lower than the global Precision.'
66+
)
67+
for issue in issues:
68+
assert issue.meta["metric"] in issue.description
69+
assert f'{issue.meta["abs_deviation_perc"]}%' in issue.description
70+
assert str(issue.slicing_fn) in issue.description
71+
6172

6273
@pytest.mark.slow
6374
def test_performance_bias_detector_with_text_features(enron_model, enron_data):

0 commit comments

Comments
 (0)