Exemplo n.º 1
0
def test_cm_functions(A, B, classes):
    cm = stats.calculate_confusion_matrix(A, B, classes)
    r1 = stats.dice_from_confusion_matrix(cm)
    r2 = stats.jaccard_from_confusion_matrix(cm)
    r3 = stats.jaccard_to_dice(r2)
    r4 = stats.dice_to_jaccard(r1)
    r5 = stats.accuracies_from_confusion_matrix(cm)
    for r in [r1, r2, r3, r4, r5]:
        assert len(r) == len(classes)
        assert not np.isnan(r).any()
    assert np.allclose(r1, r3)
    assert np.allclose(r2, r4)
    assert not np.allclose(r2, r5)
    assert not np.allclose(r1, r2)
    assert not np.allclose(r3, r4)
    assert not np.allclose(r1, r5)
    assert not np.allclose(r3, r5)
Exemplo n.º 2
0
def test_jaccard_from_cm():
    cm = np.array([[5, 2, 1], [1, 2, 1], [1, 0, 4]])
    expected = np.array([5, 2, 4], dtype=np.float) / np.array(
        [2 + 1 + 1 + 1 + 5, 2 + 1 + 1 + 2, 4 + 1 + 1 + 1], dtype=np.float)
    accs = stats.jaccard_from_confusion_matrix(cm)
    assert np.allclose(expected, accs)