def precision(predictions, targets, pos_class=1, neg_class=0):
    """precision = TP / (TP + FP)"""
    true_pos, false_pos = 0, 0
    for pred, tar in zip(predictions, targets):
        if pred == pos_class and tar == pos_class:
            true_pos += 1.0
        elif pred == pos_class and tar == neg_class:
            false_pos += 1.0
    precision = true_pos / (true_pos + false_pos)
    return {"precision": precision, "true_positive": true_pos, 
            "false_positive": false_pos}