示例#1
0
    def test_keys_and_weights(self, transform_y_t, transform_y_p, transform_gid, transform_s_w):
        a = "ABC"
        b = "DEF"
        c = "GHI"
        z = "something_longer"
        y_t = transform_y_t([0, 1, 1, 1, 0, 1, 1, 1])
        y_p = transform_y_p([0, 1, 1, 1, 1, 0, 0, 1])
        gid = transform_gid([a, z, a, b, b, c, c, c])
        s_w = transform_s_w([1, 1, 1, 5, 5, 7, 7, 7])

        metric_group_summary = metrics.make_metric_group_summary(mock_func_weight)
        metric_group_min = metrics.make_derived_metric(
            metrics.group_min_from_summary, metric_group_summary)
        metric_group_max = metrics.make_derived_metric(
            metrics.group_max_from_summary, metric_group_summary)
        metric_difference = metrics.make_derived_metric(
            metrics.difference_from_summary, metric_group_summary)
        metric_ratio = metrics.make_derived_metric(
            metrics.ratio_from_summary, metric_group_summary)

        assert metric_group_min(y_t, y_p, sensitive_features=gid, sample_weight=s_w) == 1
        assert metric_group_max(y_t, y_p, sensitive_features=gid, sample_weight=s_w) == 21
        assert metric_difference(y_t, y_p, sensitive_features=gid, sample_weight=s_w) == 20
        assert metric_ratio(y_t, y_p,
                            sensitive_features=gid, sample_weight=s_w) == pytest.approx(1.0/21.0)
示例#2
0
    def test_smoke_extra_arg(self):
        y_t = [0, 0, 1, 1, 0, 1, 1, 1]
        y_p = [0, 1, 1, 1, 1, 0, 0, 1]
        gid = [0, 0, 0, 0, 1, 1, 1, 1]

        metric_group_summary = metrics.make_metric_group_summary(mock_func_extra_arg)
        metric_group_min = metrics.make_derived_metric(
            metrics.group_min_from_summary, metric_group_summary)
        metric_group_max = metrics.make_derived_metric(
            metrics.group_max_from_summary, metric_group_summary)
        metric_difference = metrics.make_derived_metric(
            metrics.difference_from_summary, metric_group_summary)
        metric_ratio = metrics.make_derived_metric(
            metrics.ratio_from_summary, metric_group_summary)

        # Run with the extra argument defaulted
        assert metric_group_min(y_t, y_p, sensitive_features=gid) == 2
        assert metric_group_max(y_t, y_p, sensitive_features=gid) == 3
        assert metric_difference(y_t, y_p, sensitive_features=gid) == 1
        assert metric_ratio(y_t, y_p, sensitive_features=gid) == pytest.approx(0.66666666667)

        # Run with the extra argument set to something
        assert metric_group_min(y_t, y_p, sensitive_features=gid, my_arg=2) == 4
        assert metric_group_max(y_t, y_p, sensitive_features=gid, my_arg=2) == 6
        assert metric_difference(y_t, y_p, sensitive_features=gid, my_arg=2) == 2
        assert metric_ratio(y_t, y_p, sensitive_features=gid,
                            my_arg=2) == pytest.approx(0.66666666667)
示例#3
0
    def test_keys_and_weights(self, transform_y_t, transform_y_p,
                              transform_gid, transform_s_w):
        a = "ABC"
        b = "DEF"
        c = "GHI"
        z = "something_longer"
        y_t = transform_y_t([0, 1, 1, 1, 0, 1, 1, 1])
        y_p = transform_y_p([0, 1, 1, 1, 1, 0, 0, 1])
        gid = transform_gid([a, z, a, b, b, c, c, c])
        s_w = transform_s_w([1, 1, 1, 5, 5, 7, 7, 7])

        grouped_metric_func = metrics.make_metric_group_summary(
            mock_func_weight)
        result = grouped_metric_func(y_t,
                                     y_p,
                                     sensitive_features=gid,
                                     sample_weight=s_w)
        assert result.overall == 28
        assert len(result.by_group) == 4
        assert result.by_group[a] == 1
        assert result.by_group[b] == 5
        assert result.by_group[c] == 21
        assert result.by_group[z] == 1
        assert metrics.group_min_from_summary(result) == 1
        assert metrics.group_max_from_summary(result) == 21
        assert metrics.difference_from_summary(result) == 20
        assert metrics.ratio_from_summary(result) == pytest.approx(1.0 / 21.0)
示例#4
0
    def test_smoke(self):
        y_t = [0, 0, 1, 1, 0, 1, 1, 1]
        y_p = [0, 1, 1, 1, 1, 0, 0, 1]
        gid = [0, 0, 0, 0, 1, 1, 1, 1]

        grouped_metric_func = metrics.make_metric_group_summary(mock_func)
        result = grouped_metric_func(y_t, y_p, sensitive_features=gid)
        assert result.overall == 5
        assert len(result.by_group) == 2
        assert result.by_group[0] == 2
        assert result.by_group[1] == 3
        assert metrics.group_min_from_summary(result) == 2
        assert metrics.group_max_from_summary(result) == 3
        assert metrics.difference_from_summary(result) == 1
        assert metrics.ratio_from_summary(result) == pytest.approx(0.66666666667)
示例#5
0
    def test_smoke(self):
        y_t = [0, 0, 1, 1, 0, 1, 1, 1]
        y_p = [0, 1, 1, 1, 1, 0, 0, 1]
        gid = [0, 0, 0, 0, 1, 1, 1, 1]

        metric_group_summary = metrics.make_metric_group_summary(mock_func)
        metric_group_min = metrics.make_derived_metric(
            metrics.group_min_from_summary, metric_group_summary)
        metric_group_max = metrics.make_derived_metric(
            metrics.group_max_from_summary, metric_group_summary)
        metric_difference = metrics.make_derived_metric(
            metrics.difference_from_summary, metric_group_summary)
        metric_ratio = metrics.make_derived_metric(
            metrics.ratio_from_summary, metric_group_summary)

        assert metric_group_min(y_t, y_p, sensitive_features=gid) == 2
        assert metric_group_max(y_t, y_p, sensitive_features=gid) == 3
        assert metric_difference(y_t, y_p, sensitive_features=gid) == 1
        assert metric_ratio(y_t, y_p, sensitive_features=gid) == pytest.approx(0.66666666667)