Let's imagine we have a population of 1 and 0. We want then create from observed data a model able to predict if someone is a 1 or a 0. The model output have 4 possibilities:

- It predict 1 and it's really a 1. The prediction is a
**True Positive (TP)** - It predict 1 and it was supposed to be 0. The prediction is a
**False Positive (FP)** - It predict 0 and it's really a 0. The prediction is a
**True Negative (TN)** - It predict 0 and it was supposed to be a 1. The prediction is a
**False Negative (FN)**

TP = ? | FN = ? | ||

FP = ? | TN = ? |

The precision is the number of true positive divided by the number of predicted 1 : precision = TP/P̂. Thus the precision is, amoung all the time I said it's a 1, how many times I was right. So P̂ = TP+FP and likewise (to complete the table) N̂ = FN+TN.

The recall is the number of true positive divided by the number of 1 in the original dataset : precision = TP/P. Thus the recall is, amoung, all the time it was supposed to be a 1, how many time I found it.

The

The model gives for output a score between 0 and 1. By placing a threshold at different levels between 0 and 1, we can modify the precision and the recall in order to be more or less conservative.

By lowering the threshold, the orange area increase since we accept more and more people to be at 1. Thus the recall increase since we find more 1, but the precision decrease because we have more false positive.

The better the model, the smaller the precision decrease while the recall increase. Visually, it means than when we decrease the threshold, the orange area above the blue area increase less than above the green area.

By putting the threshold at 0, the orange area is the whole space, then the recall is 100% and the precision is equal to the concentration.

By putting the threshold at 1, the orange area is of size 1 (only 1 point), if this point is a true positive the recall is 1/P and the precision is 100%, if this point is a false positive the recall is 0% and the precision 0%.

Let's fix a threshold and visualize the precision and the recall.

The precision is the red area over the total orange area (visible on last graph).

The recall is the red area over the green area (visible on the first graph).

We can then plot a precision recall curve where each point is the value of the precision and the recall for a specific threshold.

Let's now consider a random choice. We have n papers in a bag written 1 or 0. We take at random m papers and our prediction is that they are all ones. In average, the precision will be the concentration, since the probability you pick a 1 is equal to the concentration. For instance, the oxygen concentration in the air is around 20%, if you fill a balloon with ambient air, the concentration of oxygen in the balloon will still be 20%. What's change is the recall, if you take a small sample of n, you will get little good 1. If you pick half the bag (playing head or tails) you will pick half of 1, so get a recall of 50%, if you pick the entire bag, the recall is 100%. Eventually, the precision-recall curve of the random strategy will be the blue horizontal line equal to the concentration on last plot.

We see that given the quite low concentration, a model that would have such a red curve would be an excellent model. For some model, the precision can start from 0%, then quickly go above the concentration line and decrease to met the concentration line for a recall of 100%.