def getErrorRates(data, thresh):
    """Returns the true positive (detection or recall rate), false positive,
    true negative, false negative, and precision rates, given some data and a threshold.
    Precision is pos/(pos+fpos).
    The data should be pairs of (value, label) pairs. For sweeping a threshold over a set of values,
    use the getAllErrorRates function instead."""
    # compute counts
    pos = sum(1.0 for c, l in data if c > thresh and l > 0)
    fpos = sum(1.0 for c, l in data if c > thresh and l <= 0)
    neg = sum(1.0 for c, l in data if c <= thresh and l <= 0)
    fneg = sum(1.0 for c, l in data if c <= thresh and l > 0)
    npos = sum(1.0 for c, l in data if l > 0)
    nneg = sum(1.0 for c, l in data if l <= 0)
    # normalize values
    try:
        precision = pos/(pos+fpos)
    except ZeroDivisionError:
        precision = 0.0
    pos /= npos
    fpos /= nneg
    neg /= nneg
    fneg /= npos
    return (pos, fpos, neg, fneg, precision)