import random


def prevalenceClassify(training, testSet, label):
    """Assumes training and testSet lists of examples
       Uses a prevalence-based classifier to predict
         whether each example in testSet is of class label
       Returns number of true positives, false positives,
          true negatives, and false negatives"""
    numWithLabel = 0
    for e in training:
        if e.getLabel()== label:
            numWithLabel += 1
    probLabel = numWithLabel/len(training)
    truePos, falsePos, trueNeg, falseNeg = 0, 0, 0, 0
    for e in testSet:
        if random.random() < probLabel: #guess label
            if e.getLabel() == label:
                truePos += 1
            else:
                falsePos += 1
        else: #guess not label
            if e.getLabel() != label:
                trueNeg += 1
            else:
                falseNeg += 1
    return truePos, falsePos, trueNeg, falseNeg