function precision_recall(predictions, labels, threshold):
   true_positives = count(p >= threshold and label == 1 for p, label in zip(predic
 tions, labels))
   predicted_positive = count(p >= threshold for p in predictions)

   actual_positive = count(label == 1 for label in labels)
   precision = true_positives / predicted_positive
   recall = true_positives / actual_positive
   return precision, recall # raising the threshold trades recall for precisio
 n
