Section 1.22

False positive and false negative

Definition

A false positive and a false negative are the two kinds of error that a binary classifier can make, where a binary classifier is any test that labels each case either positive (for example harmful) or negative (benign). A false positive is a negative case labeled positive: a false alarm. A false negative is a positive case labeled negative: a miss. Both are defined against ground truth, the true label of each case, established independently of the classifier. Statistics calls them type I and type II errors.

The idea

A detector inspects 100 programs and flags 22 of them as harmful. Whether that result is good depends on which programs really are harmful, and the detector cannot be the judge of that. If the person scoring the detector labels a program harmful because the detector flagged it, every flag counts as correct by definition, and the measured false-positive rate is zero whatever the detector does. Scoring needs ground truth that someone established without looking at the detector’s output.

The two errors have different costs. In a security monitor, a false positive costs attention or, if the monitor blocks, a legitimate action refused; a false negative is an attack that goes unnoticed or unblocked. One setting usually trades one error for the other, as with a smoke detector’s sensitivity. Set high, it sounds for burnt toast; set low, it may stay silent during a real fire. The analogy stops at cost: an alarm about toast is cheap, while a false positive that blocks a safety-critical command can do as much harm as a miss.

How it works

Fix the unit. Decide what one case is: a packet, a request, a program, one execution of a program, or a device. All counts are counts of that unit. A harmful program can run many times without harm, because its harmful path needs a particular input. Labeled per execution, those runs are negatives; labeled per program, the program is a positive. Mixing units changes what counts as an error.

Name the positive class. In security, positive usually means flagged as harmful, so a false positive is a benign case that was flagged. Where a component accepts or rejects, say which outcome counts as positive. For a verifier, a checker that admits only programs it can show to be safe, take rejection as positive: a false positive is a safe program rejected, and a false negative is an unsafe program accepted. A sound verifier, one that never accepts an unsafe program, has no false negatives by design and pays for that with false positives. This trade is called conservative refusal §3.36.

Establish ground truth before scoring, without the detector. Four sources are used, alone or together.

Count the four outcomes. A true positive (TP) is a harmful case flagged; a false negative (FN) is a harmful case not flagged; a false positive (FP) is a benign case flagged; a true negative (TN) is a benign case not flagged. The table of these four counts is called a confusion matrix. Cases where the detector gave no answer, for example because it timed out, and cases whose true label could not be settled are counted separately, not silently added to one of the four.

Divide by the right total. The true positive rate (TPR) is the fraction of harmful cases flagged; it is also called sensitivity, recall or detection rate. The false negative rate (FNR), or miss rate, is the fraction of harmful cases missed. The false positive rate (FPR), or false-alarm rate, is the fraction of benign cases flagged. The true negative rate (TNR), or specificity, is the fraction of benign cases not flagged. The positive predictive value (PPV), also called precision, is the fraction of flagged cases that are really harmful. Each rate answers a different question, and swapping the totals changes the meaning.

Worked example

A test set has 100 cases whose labels were fixed by construction: 20 harmful and 80 benign. The detector flags 18 of the harmful cases and 4 of the benign ones.

flagged not flagged
harmful (20 cases) TP = 18 FN = 2
benign (80 cases) FP = 4 TN = 76

The four counts add up to 18+2+4+76=10018 + 2 + 4 + 76 = 100. The rates are: TPR =18/20=0.90= 18 / 20 = 0.90; FNR =2/20=0.10= 2 / 20 = 0.10; FPR =4/80=0.05= 4 / 80 = 0.05; TNR =76/80=0.95= 76 / 80 = 0.95. The detector flagged 18+4=2218 + 4 = 22 cases, of which 18 are harmful, so PPV =18/22≈0.818= 18 / 22 \approx 0.818: about 82% of its alarms are real. Accuracy, the fraction of all cases labeled correctly, is (18+76)/100=0.94(18 + 76) / 100 = 0.94.

Accuracy alone misleads when one class is rare. A detector that flags nothing has accuracy 80/100=0.8080 / 100 = 0.80 on this set and catches no harmful case at all.

The share of real alarms depends on how common harmful cases are. Keep the same rates, TPR =0.90= 0.90 and FPR =0.05= 0.05, and apply the detector to 1000 cases of which 10 are harmful and 990 benign. The expected number of true positives is 0.90×10=90.90 \times 10 = 9. The expected number of false positives is 0.05×990=49.50.05 \times 990 = 49.5; a count of half a case is fine for an expected value, which is an average over many repetitions. PPV =9/(9+49.5)=9/58.5≈0.154= 9 / (9 + 49.5) = 9 / 58.5 \approx 0.154. Now only about 15% of alarms are real and about 85% are false, although the false positive rate is still 5%. A detector that flags nothing would score accuracy 990/1000=0.99990 / 1000 = 0.99 on this set.

Stated precisely

Let PP be the number of cases whose ground-truth label is positive and NN the number whose label is negative. With the four counts defined above, TP+FN=P\mathrm{TP} + \mathrm{FN} = P and FP+TN=N\mathrm{FP} + \mathrm{TN} = N. The rates are TPR=TP/P,FNR=FN/P=1−TPR,FPR=FP/N,TNR=TN/N=1−FPR,\begin{aligned} \mathrm{TPR} &= \mathrm{TP} / P, & \mathrm{FNR} &= \mathrm{FN} / P = 1 - \mathrm{TPR}, \\ \mathrm{FPR} &= \mathrm{FP} / N, & \mathrm{TNR} &= \mathrm{TN} / N = 1 - \mathrm{FPR}, \end{aligned} and PPV=TP/(TP+FP)\mathrm{PPV} = \mathrm{TP} / (\mathrm{TP} + \mathrm{FP}). TPR and FPR are each computed within one true class, so they do not depend on how many cases of each class the set contains.

Let π\pi be the prevalence, the fraction of cases in a population that are truly positive. Over that population, Bayes’ theorem gives the expected positive predictive value PPV=TPR⋅πTPR⋅π+FPR⋅(1−π).\mathrm{PPV} = \frac{\mathrm{TPR} \cdot \pi}{\mathrm{TPR} \cdot \pi + \mathrm{FPR} \cdot (1 - \pi)}. With TPR=0.90\mathrm{TPR} = 0.90, FPR=0.05\mathrm{FPR} = 0.05 and π=0.01\pi = 0.01, this is 0.009/(0.009+0.0495)≈0.1540.009 / (0.009 + 0.0495) \approx 0.154, as in the example. PPV therefore depends on the prevalence, and a PPV measured on a test set holds only for a population with the test set’s mix of classes.

In statistical hypothesis testing, the null hypothesis, the default claim that there is no effect, plays the role of the negative label. A type I error rejects a null hypothesis that is true, which is a false positive. A type II error fails to reject a null hypothesis that is false, which is a false negative. The Roman numerals I and II only number the two kinds.

A detector that computes a score and flags every case above a threshold has one pair of rates for each threshold. Raising the threshold flags fewer cases, so neither rate can rise: false alarms fall, and so do detections. The curve of all (FPR, TPR) pairs is the receiver operating characteristic (ROC) curve, and choosing a threshold means choosing a point on it.

Limits and common mistakes

Ground truth taken from the detector, or from a tool that shares its logic, makes the evaluation circular. Every flag then agrees with the labels, and the shared mistakes never appear as errors.

Zero observed errors do not mean a zero error rate. With 0 false negatives among 60 independent harmful cases, the true miss rate can still be as high as about 5%: the upper end of a one-sided 95% confidence interval §11.18 is 1−0.051/60≈0.0491 - 0.05^{1/60} \approx 0.049, close to the rule-of-three §18.5.8 value 3/60=0.053 / 60 = 0.05.

Rare positives make alarms mostly false unless the false positive rate is tiny. Stefan Axelsson’s paper “The Base-Rate Fallacy and the Difficulty of Intrusion Detection” (2000) [413] applied this arithmetic to intrusion detection, where attacks are a very small fraction of all events.

Cases that are not independent overstate the evidence. Fifty small variants of one exploit, an input or program built to take advantage of a flaw, count as 50 cases but test about one behavior; treating them as 50 independent cases is a form of pseudoreplication §11.6. A test set chosen because the detector handles it well inflates the true positive rate.

The names follow the choice of positive class. Calling “accepted” positive instead of “rejected” swaps which error is the false positive, so every report must say which class is positive and what one case is.

Questions answered

How were benign and harmful ground truth established independently?

Benign and harmful ground truth is established independently when every case’s label comes from a source that never sees the detector’s output and shares none of the detector’s logic, and when the labels are fixed before the detector is scored. Ground truth means the true label of each case, against which the detector’s false positives (benign cases flagged) and false negatives (harmful cases missed) are counted. An evaluation must state which source produced each label. The usual sources are:

Independence is then checked, not assumed. Each harmful case should be shown to cause its harm, for example by observing the violation when the case runs without the detector, and each benign case shown to work as intended. The oracle must not share code or rules with the detector, or both will make the same mistakes. The unit of a case (packet, program or execution) is stated, and cases whose label could not be settled are reported separately rather than assigned to either class. A label that says a case is harmful because the detector rejected it is not ground truth: it makes every rejection correct by definition.

Related entries: Estimand and estimator (§11.2), Confidence interval (§11.18), Conservative refusal (§3.36), Test oracle (§10.5), Zero observed failures and the rule of three (§18.5.8), Semantic oracle independence and common-mode errors (§19.2.13). Further reading: [413].