def test_inequality():
    a = GroupMetricSet()
    b = GroupMetricSet()

    a.compute(Y_true,
              Y_pred,
              groups,
              model_type=GroupMetricSet.BINARY_CLASSIFICATION)
    b.compute(Y_true,
              Y_pred,
              gr_alp,
              model_type=GroupMetricSet.BINARY_CLASSIFICATION)

    assert not (a == b)
    assert a != b
def test_groups_not_sequential_int():
    target = GroupMetricSet()
    regular = GroupMetricSet()

    # Make 'target' the same as 'regular' but with different integers for the groups
    target.compute(Y_true,
                   Y_pred,
                   gr_in2,
                   model_type=GroupMetricSet.BINARY_CLASSIFICATION)
    regular.compute(Y_true,
                    Y_pred,
                    groups,
                    model_type=GroupMetricSet.BINARY_CLASSIFICATION)

    assert np.array_equal(['2', '4'], target.group_names)

    assert target.metrics == regular.metrics
def test_compute_binary():
    target = GroupMetricSet()

    target.compute(Y_true,
                   Y_pred,
                   groups,
                   model_type=GroupMetricSet.BINARY_CLASSIFICATION)

    sample_expected = group_accuracy_score(Y_true, Y_pred, groups)

    assert np.array_equal(Y_true, target.y_true)
    assert np.array_equal(Y_pred, target.y_pred)
    assert np.array_equal(groups, target.groups)
    assert np.array_equal(['0', '1'], target.group_names)
    assert len(target.metrics) == 10
    assert target.metrics[
        GroupMetricSet.GROUP_ACCURACY_SCORE].overall == sample_expected.overall
    for g in np.unique(groups):
        assert (target.metrics[GroupMetricSet.GROUP_ACCURACY_SCORE].by_group[g]
                == sample_expected.by_group[g])
def test_compute_regression():
    target = GroupMetricSet()

    target.compute(Y_true,
                   Y_pred,
                   groups,
                   model_type=GroupMetricSet.REGRESSION)

    sample_expected = group_balanced_root_mean_squared_error(
        Y_true, Y_pred, groups)

    assert np.array_equal(Y_true, target.y_true)
    assert np.array_equal(Y_pred, target.y_pred)
    assert np.array_equal(groups, target.groups)
    assert np.array_equal(['0', '1'], target.group_names)
    assert len(target.metrics) == 12
    assert target.metrics[
        GroupMetricSet.
        GROUP_BALANCED_ROOT_MEAN_SQUARED_ERROR].overall == sample_expected.overall  # noqa: E501
    for g in np.unique(groups):
        assert (target.metrics[
            GroupMetricSet.GROUP_BALANCED_ROOT_MEAN_SQUARED_ERROR].by_group[g]
                == sample_expected.by_group[g])
def test_groups_alphabetical():
    target = GroupMetricSet()
    regular = GroupMetricSet()

    # Make 'target' the same as 'regular' but with strings for the groups
    target.compute(Y_true,
                   Y_pred,
                   gr_alp,
                   model_type=GroupMetricSet.BINARY_CLASSIFICATION)
    regular.compute(Y_true,
                    Y_pred,
                    groups,
                    model_type=GroupMetricSet.BINARY_CLASSIFICATION)

    assert np.array_equal(['a', 'b'], target.group_names)

    tm = target.metrics[GroupMetricSet.GROUP_ACCURACY_SCORE]
    rm = target.metrics[GroupMetricSet.GROUP_ACCURACY_SCORE]

    assert tm.overall == rm.overall
    assert tm.by_group == rm.by_group
    assert tm == rm

    assert target.metrics == regular.metrics