forked from tensorflow/model-analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add precision and recall to fairness indicators metrics.
PiperOrigin-RevId: 447761681
- Loading branch information
1 parent
b499acf
commit dfe9d55
Showing
2 changed files
with
68 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,8 +72,7 @@ def check_result(got): | |
self.assertLen(got, 1) | ||
got_slice_key, got_metrics = got[0] | ||
self.assertEqual(got_slice_key, ()) | ||
self.assertLen(got_metrics, 16) # 2 thresholds * 8 metrics | ||
self.assertDictElementsAlmostEqual( | ||
np.testing.assert_equal( | ||
got_metrics, { | ||
metric_types.MetricKey( | ||
name='fairness_indicators_metrics/[email protected]' | ||
|
@@ -105,6 +104,12 @@ def check_result(got): | |
name='fairness_indicators_metrics/[email protected]' | ||
): | ||
0.0, | ||
metric_types.MetricKey( | ||
name='fairness_indicators_metrics/[email protected]'): | ||
2.0 / 3.0, | ||
metric_types.MetricKey( | ||
name='fairness_indicators_metrics/[email protected]'): | ||
1.0, | ||
metric_types.MetricKey( | ||
name='fairness_indicators_metrics/[email protected]' | ||
): | ||
|
@@ -134,7 +139,13 @@ def check_result(got): | |
metric_types.MetricKey( | ||
name='fairness_indicators_metrics/[email protected]' | ||
): | ||
1.0 / 3.0 | ||
1.0 / 3.0, | ||
metric_types.MetricKey( | ||
name='fairness_indicators_metrics/[email protected]'): | ||
1.0, | ||
metric_types.MetricKey( | ||
name='fairness_indicators_metrics/[email protected]'): | ||
0.5 | ||
}) | ||
except AssertionError as err: | ||
raise util.BeamAssertException(err) | ||
|
@@ -176,7 +187,7 @@ def check_result(got): | |
self.assertLen(got, 1) | ||
got_slice_key, got_metrics = got[0] | ||
self.assertEqual(got_slice_key, ()) | ||
self.assertLen(got_metrics, 8) # 1 threshold * 8 metrics | ||
self.assertLen(got_metrics, 10) # 1 threshold * 10 metrics | ||
self.assertTrue( | ||
math.isnan(got_metrics[metric_types.MetricKey( | ||
name='fairness_indicators_metrics/[email protected]')])) | ||
|
@@ -190,10 +201,10 @@ def check_result(got): | |
util.assert_that(result, check_result, label='result') | ||
|
||
@parameterized.named_parameters( | ||
('_default_threshold', {}, 72, ()), | ||
('_default_threshold', {}, 90, ()), | ||
('_thresholds_with_different_digits', { | ||
'thresholds': [0.1, 0.22, 0.333] | ||
}, 24, (metric_types.MetricKey( | ||
}, 30, (metric_types.MetricKey( | ||
name='fairness_indicators_metrics/[email protected]', | ||
example_weighted=True), | ||
metric_types.MetricKey( | ||
|
@@ -276,6 +287,14 @@ def check_result(got): | |
name='fairness_indicators_metrics/[email protected]', | ||
example_weighted=True): | ||
0.25, | ||
metric_types.MetricKey( | ||
name='fairness_indicators_metrics/[email protected]', | ||
example_weighted=True): | ||
float('nan'), | ||
metric_types.MetricKey( | ||
name='fairness_indicators_metrics/[email protected]', | ||
example_weighted=True): | ||
float('nan'), | ||
metric_types.MetricKey( | ||
name='fairness_indicators_metrics/[email protected]', | ||
example_weighted=True): | ||
|
@@ -284,6 +303,17 @@ def check_result(got): | |
name='fairness_indicators_metrics/[email protected]', | ||
example_weighted=True): | ||
1.0, | ||
metric_types.MetricKey( | ||
name='fairness_indicators_metrics/[email protected]', | ||
example_weighted=True): | ||
0.0, | ||
metric_types.MetricKey( | ||
name='fairness_indicators_metrics/[email protected]', | ||
example_weighted=True): | ||
0.0, | ||
metric_types.MetricKey( | ||
name='fairness_indicators_metrics/[email protected]', example_weighted=True): | ||
float('nan'), | ||
}), ('_has_model_name', [{ | ||
'labels': np.array([0.0]), | ||
'predictions': { | ||
|
@@ -315,6 +345,16 @@ def check_result(got): | |
model_name='model1', | ||
example_weighted=True): | ||
0.25, | ||
metric_types.MetricKey( | ||
name='fairness_indicators_metrics/[email protected]', | ||
model_name='model1', | ||
example_weighted=True): | ||
float('nan'), | ||
metric_types.MetricKey( | ||
name='fairness_indicators_metrics/[email protected]', | ||
model_name='model1', | ||
example_weighted=True): | ||
float('nan'), | ||
metric_types.MetricKey( | ||
name='fairness_indicators_metrics/[email protected]', | ||
model_name='model1', | ||
|
@@ -325,6 +365,21 @@ def check_result(got): | |
model_name='model1', | ||
example_weighted=True): | ||
1.0, | ||
metric_types.MetricKey( | ||
name='fairness_indicators_metrics/[email protected]', | ||
model_name='model1', | ||
example_weighted=True): | ||
0.0, | ||
metric_types.MetricKey( | ||
name='fairness_indicators_metrics/[email protected]', | ||
model_name='model1', | ||
example_weighted=True): | ||
0.0, | ||
metric_types.MetricKey( | ||
name='fairness_indicators_metrics/[email protected]', | ||
model_name='model1', | ||
example_weighted=True): | ||
float('nan'), | ||
})) | ||
def testFairessIndicatorsMetricsWithInput(self, input_examples, | ||
computations_kwargs, | ||
|
@@ -360,10 +415,7 @@ def check_result(got): | |
self.assertLen(got, 1) | ||
got_slice_key, got_metrics = got[0] | ||
self.assertEqual(got_slice_key, ()) | ||
self.assertLen(got_metrics, 8) # 1 threshold * 8 metrics | ||
for metrics_key in expected_result: | ||
self.assertEqual(got_metrics[metrics_key], | ||
expected_result[metrics_key]) | ||
np.testing.assert_equal(got_metrics, expected_result) | ||
except AssertionError as err: | ||
raise util.BeamAssertException(err) | ||
|
||
|