Exemplo n.º 1
0
def test_shape_accuracy4():
    x = Tensor(np.array([[0.2, 0.5], [0.3, 0.1], [0.9, 0.6]]))
    y = Tensor(np.array(1))
    metric = Accuracy('classification')
    metric.clear()
    with pytest.raises(ValueError):
        metric.update(x, y)
Exemplo n.º 2
0
def test_shape_accuracy2():
    x = Tensor(np.array([[0, 1, 0, 1], [1, 0, 1, 1], [0, 0, 0, 1]]))
    y = Tensor(np.array([0, 1, 1, 1]))
    metric = Accuracy('multilabel')
    metric.clear()
    with pytest.raises(ValueError):
        metric.update(x, y)
Exemplo n.º 3
0
def test_multilabel_accuracy():
    x = Tensor(np.array([[0, 1, 0, 1], [1, 0, 1, 1], [0, 0, 0, 1]]))
    y = Tensor(np.array([[0, 1, 1, 1], [0, 1, 1, 1], [0, 0, 0, 1]]))
    metric = Accuracy('multilabel')
    metric.clear()
    metric.update(x, y)
    accuracy = metric.eval()
    assert accuracy == 1 / 3
Exemplo n.º 4
0
def test_classification_accuracy_indexes_awareness():
    """A indexes aware version of test_classification_accuracy"""
    x = Tensor(np.array([[0.2, 0.5], [0.3, 0.1], [0.9, 0.6]]))
    y = Tensor(np.array([1, 0, 1]))
    y2 = Tensor(np.array([0, 0, 1]))
    metric = Accuracy('classification').set_indexes([0, 2])
    metric.clear()
    metric.update(x, y, y2)
    accuracy = metric.eval()
    assert math.isclose(accuracy, 1 / 3)
Exemplo n.º 5
0
def test_classification_accuracy():
    """test_classification_accuracy"""
    x = Tensor(np.array([[0.2, 0.5], [0.3, 0.1], [0.9, 0.6]]))
    y = Tensor(np.array([1, 0, 1]))
    y2 = Tensor(np.array([[0, 1], [1, 0], [0, 1]]))
    metric = Accuracy('classification')
    metric.clear()
    metric.update(x, y)
    accuracy = metric.eval()
    accuracy2 = metric(x, y2)
    assert math.isclose(accuracy, 2 / 3)
    assert math.isclose(accuracy2, 2 / 3)