def test_keys_and_weights(self, transform_y_a, transform_y_p,
                              transform_gid, transform_s_w):
        a = "ABC"
        b = "DEF"
        c = "GHI"
        z = "something_longer"
        y_a = transform_y_a([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_group_metric(mock_func_weight)
        result = grouped_metric_func(y_a, y_p, gid, 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 result.minimum == 1
        assert result.maximum == 21
        assert result.argmin_set == {a, z}
        assert result.argmax_set == {c}
        assert result.range == 20
        assert result.range_ratio == pytest.approx(1.0 / 21.0)
Exemplo n.º 2
0
    def test_smoke(self):
        y_a = [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_group_metric(mock_func)
        result = grouped_metric_func(y_a, y_p, 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)
    def test_smoke(self):
        y_a = [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_group_metric(mock_func)
        result = grouped_metric_func(y_a, y_p, gid)
        assert result.overall == 5
        assert len(result.by_group) == 2
        assert result.by_group[0] == 2
        assert result.by_group[1] == 3
        assert result.minimum == 2
        assert result.maximum == 3
        assert result.argmin_set == {0}
        assert result.argmax_set == {1}
        assert result.range == 1
        assert result.range_ratio == pytest.approx(0.66666666667)
Exemplo n.º 4
0
    def test_keys_and_weights(self, transform_y_a, transform_y_p,
                              transform_gid, transform_s_w):
        a = "ABC"
        b = "DEF"
        c = "GHI"
        z = "something_longer"
        y_a = transform_y_a([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_group_metric(mock_func_weight)
        result = grouped_metric_func(y_a, y_p, 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)