Esempio n. 1
0
def test_evaluation_library_n_best(GNB):
    """ Test `n_best` normal usage.  """
    lib = EvaluationLibrary(m=None, sample=None, cache=_short_name())

    try:
        best_evaluation = _mock_evaluation(GNB, score=(1.0, 1.0, 1.0))
        worst_evaluation = _mock_evaluation(GNB, score=(0.0, 0.0, 0.0))
        lib.save_evaluation(best_evaluation)
        lib.save_evaluation(worst_evaluation)

        for _ in range(10):
            lib.save_evaluation(_mock_evaluation(GNB))

        assert (
            len(lib.n_best(10)) == 10
        ), "n_best(10) should return 10 results as more than 10 evaluations are saved."
        assert (
            best_evaluation is lib.n_best(10)[0]
        ), "`best_evaluation` should be number one in `n_best`"
        assert worst_evaluation not in lib.n_best(
            10
        ), "`worst_evaluation` should not be in the top 10 of 12 evaluations."
        assert (
            len(lib.n_best(100)) == 12
        ), "`n > len(lib.top_evaluations)` should return all evaluations."
    finally:
        lib.clear_cache()
Esempio n. 2
0
def test_evaluation_library_n_best(GaussianNB):
    """ Test `max_number_of_evaluations` correctly restricts the number of evaluations in `top_evaluations`. """
    lib = EvaluationLibrary(m=None, sample=None)

    best_evaluation = _mock_evaluation(GaussianNB, score=(1., 1., 1.))
    worst_evaluation = _mock_evaluation(GaussianNB, score=(0., 0., 0.))
    lib.save_evaluation(best_evaluation)
    lib.save_evaluation(worst_evaluation)

    for _ in range(10):
        lib.save_evaluation(_mock_evaluation(GaussianNB))

    assert len(
        lib.n_best(10)
    ) == 10, "n_best(10) should return 10 results as more than 10 evaluations are saved."
    assert best_evaluation is lib.n_best(
        10)[0], "`best_evaluation` should be number one in `n_best`"
    assert worst_evaluation not in lib.n_best(
        10
    ), "`worst_evaluation` should not be in the top 10 of 12 evaluations."
    assert len(
        lib.n_best(100)
    ) == 12, "`n > len(lib.top_evaluations)` should return all evaluations."