Esempio n. 1
0
def test_categorical_accuracy():
    y = [0, 1, 2, 3, 4]
    y_pred = [0, 1, 2, 2, 3]
    assert metrics.categorical_accuracy(y, y_pred) == [1, 1, 1, 0, 0]
    assert metrics.categorical_accuracy(y, np.eye(5)) == [1] * 5
    with pytest.raises(ValueError):
        metrics.categorical_accuracy(y, [[y_pred]])
Esempio n. 2
0
def test_top_n_categorical_accuracy():
    y = [0, 1, 2, 3, 4]
    y_pred = [0, 1, 2, 2, 3]
    assert metrics.categorical_accuracy(
        y, y_pred) == metrics.top_n_categorical_accuracy(y, y_pred, 1)
    y = [2, 0]
    y_pred = [[0.1, 0.4, 0.2, 0.2, 0.1, 0.1], [0.1, 0.4, 0.2, 0.2, 0.1, 0.1]]
    assert metrics.top_n_categorical_accuracy(y, y_pred, 3) == [1, 0]