def precision(classifier, testset):

    hit = 0
    total = 0
    for example in testset:
        if classifier.classify(example)[0] == classifier.target(example):
            hit += 1
        total += 1
    if total == 0:
        raise ValueError("Empty testset!")
    return hit / float(total)
Doctests should be runnable repeatably.
dataset/ETHPy150Open simpleai-team/simpleai/simpleai/machine_learning/evaluation.py/precision--crossover with--dataset/ETHPy150Open kuri65536/python-for-android/python-modules/twisted/twisted/trial/test/test_doctest.py/TestRunners.test_repeatable