Answers.Body: <p>The tradeoff between precision and recall occurs because increasing the threshold for classification will result in fewer false positives (increasing precision) but also more false negatives (decreasing recall), and vice versa. You cannot eliminate both false positives and false negatives simultaneously without the presence of a perfect classifier, so improving one often comes at the cost of the other.</p>
  <p>But you can do is picking the best threshold for the trade-off from what you have. For example:</p>
  <p>You can calculate Youden's J statistic <span class="math-container">$J = TPR - FPR$</span> for finding threshold:</p>
  <pre><code>J = tpr - fpr
  # Get the index of the maximum J statistic
  max_j_index = np.argmax(J)
  # Get the best threshold value
  best_threshold_j = thresholds[max_j_index]
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-24T22:28:39.013Z
Answers.LastActivityDate: 2023-11-24T22:28:39.013Z
Answers.UserDisplayName: lkahtz
Answers.Body: <p>Your mentioned so called precision and recall tradeoff is a statistical tendency on average, not a mathematical necessity which can be easily shown in below example.</p>
  <p>Let <span class="math-container">$TP=10, FP=5, FN=5$</span> for demonstration purposes of a trained (non-optimal) classifier, then <span class="math-container">$$\text{precision} = 10/(10+5) \approx 0.67, \text{recall} = 10/(10+5) \approx 0.67$$</span></p>
  <p>Now let's say we improved the classifier to increase its precision by reducing false positives while keeping true positives constant, ie, now <span class="math-container">$TP=10, FP=2, FN=5$</span>, then <span class="math-container">$$\text{precision} = 10/(10+2) \approx 0.83, \text{recall} = 10/(10+5) \approx 0.67$$</span></p>
  <p>Thus recall <em>remains the same</em> despite precision increases in this case. Usually you can define a single <a href="https://en.wikipedia.org/wiki/F-score" rel="nofollow noreferrer">F-score</a> as weighted harmonic mean of both precision and recall to tradeoff and effectively weigh the lower of the two numbers more heavily.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-25T00:48:56.367Z
Answers.LastActivityDate: 2023-11-25T01:35:22.227Z
Answers.LastEditDate: 2023-11-25T01:35:22.227Z
Answers.UserDisplayName: cinch
Body: <p>Is there a mathematical explanation of precision and recall tradeoff? Ie, is it possible
  mathematically to see that as you increase one, the other decreases?</p>
  <p><span class="math-container">$\text{Precision}=\frac{TP}{P^*}=\frac{TP}{TP+FP}$</span></p>
  <p><span class="math-container">$\text{Recall}=\frac{TP}{P}=\frac{TP}{TP+FN}$</span>.</p>
  <p>When precision increases, why does Recall decease?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-11-24T18:20:05.380Z
Comments.Text: no, you can have definitely perfect precision and perfect recall
Comments.UserDisplayName: Alberto
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-11-24T19:28:25.027Z
Comments.Text: but in almost all ML material, they mention this tradeoff.
Comments.UserDisplayName: DSPinfinity
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-11-24T21:08:23.957Z
Comments.Text: because you can have ideally the perfect classifier that nails both of them, but we don't have it
Comments.UserDisplayName: Alberto
Tags: <machine-learning><classification>
Title: is there a mathematical explanation of precision and recall tradeoff?
UserDisplayName: DSPinfinity
ThreadText: # is there a mathematical explanation of precision and recall tradeoff?
  
  (Asked by: username_0 on 2023-11-24)
  
  Is there a mathematical explanation of precision and recall tradeoff? Ie, is it possible
  mathematically to see that as you increase one, the other decreases?
  
  $\text{Precision}=\frac{TP}{P^\*}=\frac{TP}{TP+FP}$
  
  $\text{Recall}=\frac{TP}{P}=\frac{TP}{TP+FN}$.
  
  When precision increases, why does Recall decease?
  
  **Tags:** machine-learning, classification
  > **Comments:**
  > **username_1**: no, you can have definitely perfect precision and perfect recall  
  > **username_0**: but in almost all ML material, they mention this tradeoff.  
  > **username_1**: because you can have ideally the perfect classifier that nails both of them, but we don't have it  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2023-11-25. Score: 2 | Accepted answer
  
  Your mentioned so called precision and recall tradeoff is a statistical tendency on average, not a mathematical necessity which can be easily shown in below example.
  
  Let $TP=10, FP=5, FN=5$ for demonstration purposes of a trained (non-optimal) classifier, then $$\text{precision} = 10/(10+5) \approx 0.67, \text{recall} = 10/(10+5) \approx 0.67$$
  
  Now let's say we improved the classifier to increase its precision by reducing false positives while keeping true positives constant, ie, now $TP=10, FP=2, FN=5$, then $$\text{precision} = 10/(10+2) \approx 0.83, \text{recall} = 10/(10+5) \approx 0.67$$
  
  Thus recall *remains the same* despite precision increases in this case. Usually you can define a single [F-score](https://en.wikipedia.org/wiki/F-score) as weighted harmonic mean of both precision and recall to tradeoff and effectively weigh the lower of the two numbers more heavily.
  
  
  ---
  
  ### Answer by username_2 on 2023-11-24. Score: 3
  
  The tradeoff between precision and recall occurs because increasing the threshold for classification will result in fewer false positives (increasing precision) but also more false negatives (decreasing recall), and vice versa. You cannot eliminate both false positives and false negatives simultaneously without the presence of a perfect classifier, so improving one often comes at the cost of the other.
  But you can do is picking the best threshold for the trade-off from what you have. For example:
  You can calculate Youden's J statistic $J = TPR - FPR$ for finding threshold:
  J = tpr - fpr
  # Get the index of the maximum J statistic
  max_j_index = np.argmax(J)
  # Get the best threshold value
  best_threshold_j = thresholds[max_j_index]
  
  
  ---
  
  