Exemplo n.º 1
0
def test_confusion_matrix():
    """test_confusion_matrix"""
    x = Tensor(np.array([1, 0, 1, 0]))
    y = Tensor(np.array([1, 0, 0, 1]))
    metric = ConfusionMatrix(num_classes=2)
    metric.clear()
    metric.update(x, y)
    output = metric.eval()

    assert np.allclose(output, np.array([[1, 1], [1, 1]]))
Exemplo n.º 2
0
def test_confusion_matrix_update_len():
    x = Tensor(np.array([[0.2, 0.5, 0.7], [0.3, 0.1, 0.2], [0.9, 0.6, 0.5]]))
    metric = ConfusionMatrix(num_classes=2)
    metric.clear()

    with pytest.raises(ValueError):
        metric.update(x)
Exemplo n.º 3
0
def test_confusion_matrix_runtime():
    metric = ConfusionMatrix(num_classes=2)
    metric.clear()

    with pytest.raises(RuntimeError):
        metric.eval()
Exemplo n.º 4
0
def test_confusion_matrix_init_threshold():
    with pytest.raises(TypeError):
        ConfusionMatrix(num_classes=2, normalize='no_norm', threshold=1)
Exemplo n.º 5
0
def test_confusion_matrix_init_normalize_value():
    with pytest.raises(ValueError):
        ConfusionMatrix(num_classes=2, normalize="wwe")
Exemplo n.º 6
0
def test_confusion_matrix_init_num_classes():
    with pytest.raises(TypeError):
        ConfusionMatrix(num_classes='1')