Perception · Theory · P6
P6-T6 — False Positives, False Negatives and Domain Shift
A false alarm and a miss are different failures with different prices, and the world changes under a model after it is trained.
Every detector makes two kinds of mistake. It reports something that is not there, and it misses something that is. Which one hurts depends on the robot: a vacuum that stops for a shadow is annoying, a car that misses a pedestrian is unacceptable. A second problem comes on top: the data the detector sees at run time differ from the data it was built and tested on, in lighting, weather, place, sensor or object mix, and the error rates move. This lesson treats both. It shows how costs set a threshold, why base rates can make a good detector produce mostly false alarms, how a confirmation rule trades delay for fewer false alarms, and how to evaluate and watch for shift. Labs P6-L3 and P6-L4 practise the first and second halves.
Learning objectives
After this lesson, you should be able to:
- Explain what false positives and false negatives cost in different robot tasks and why they cannot both be zero.
- Derive the threshold for a calibrated score from the two costs and compute precision from recall, false alarm rate and prevalence.
- Show how requiring several consecutive detections cuts false alarms and what delay it adds.
- Distinguish covariate, prior and concept shift and plan an evaluation by condition that exposes the worst case.
The idea: two errors, two prices, and a moving world
A false positive is a detection with nothing behind it: a shadow taken for an obstacle, a poster taken for a person. A false negative is an object the system did not report. They are not opposites of a single dial, because the detector’s score can rank them only imperfectly. Moving the threshold trades one for the other along the precision-recall curve (Lesson P6-T5), and no threshold removes both.
What each costs
The two errors have different consequences, and the consequences differ by task.
| Task | False positive costs | False negative costs | Usual lean |
|---|---|---|---|
| Warehouse robot avoiding people | an unneeded stop, lost time | a collision risk | accept more false alarms |
| Sorting parts by class | a good part is rejected | a bad part gets through | depends on the part |
| Monitoring inspection images | an engineer checks a clean image | a defect goes unseen | accept more false alarms |
| Counting objects for inventory | overcount | undercount | balanced |
The table shows why one metric cannot serve every task. The cost ratio is a property of the application, and it has to come from outside the detector, from a safety or cost analysis.
False alarms add up over time
A robot sees ten frames a second, thirty-six thousand frames an hour. A false-alarm rate of 1 in 20 frames means a false alarm every two seconds, which is unusable even though the detector looks 95% right. Rates that sound small are large per hour, and the right unit for a false-alarm requirement is per hour or per kilometre, not per frame.
The world changes
A detector’s error rates are measured on a sample. If the deployment differs from the sample, they change. Three kinds of change are worth naming.
- Covariate shift. The inputs change but the meaning of the labels does not: dusk instead of day, a new camera, rain on the lens, a different warehouse. The same object looks different and the detector may no longer recognise it.
- Prior (label) shift. The frequency of the classes or of the objects changes: pedestrians are rare in an empty site and common near a gate. The detector is unchanged, but its precision is not (see the formulas).
- Concept shift. What the label means changes: a new type of pallet, a changed rule about what counts as an obstacle. The old training no longer matches the task.
The mathematics: costs, base rates and confirmation
A threshold from costs. Let a detection carry a calibrated probability p of being a real object. Reporting it costs Cfp if it is wrong and, if it is right, avoids a miss costing Cmiss. The expected cost of ignoring the detection is p · Cmiss; the expected cost of acting on it is (1 − p) · Cfp. Act when the first is larger:
- p
- the probability that the detection is a real object. This requires calibrated scores; for uncalibrated scores the same logic holds but the threshold on the score must be found from validation data, as in Lab P6-L3.
- Cmiss, Cfp
- the costs of a missed object and of a false alarm, in any common unit (money, stop time, risk points).
When a miss costs ten times a false alarm, the threshold on p is 1/11 ≈ 0.09, very low. When they cost the same it is 0.5. The detector’s “default” threshold has no special meaning.
Precision depends on prevalence. Let the detector find a real object with probability s (the recall or sensitivity) and raise a false alarm on a non-object with probability f. If the fraction of candidate locations that hold an object is π (the prevalence), then
- s
- sensitivity: probability that a real object is detected (recall).
- f
- false alarm rate: probability that a non-object location is reported.
- π
- prevalence: the share of examined locations or frames that contain an object.
The same detector, with unchanged s and f, has a lower precision when objects get rarer.
Confirmation over time. If a false alarm occurs in each frame independently with probability q, requiring m consecutive detections before acting gives a false-alarm probability of qm per start frame. The price is a delay of about (m − 1) frames before a real object is confirmed, and a lower chance of confirming it if the detector misses often. Independence is optimistic: errors that persist, such as a poster, are not removed by waiting. This is the first step toward tracking (Module 7).
Worked examples
1. The prevalence effect. A detector has sensitivity s = 0.90 and a false-alarm rate f = 0.05 per candidate. Where 10% of the candidate locations hold an object (π = 0.10):
Where objects are rare, π = 0.01:
The detector is unchanged, but only about one detection in six is real. Recall stayed at 0.90, so a test set rich in objects would never reveal the problem.
2. Confirmation. A per-frame false-alarm probability of q = 0.05 at 10 frames a second, with m = 3 required: q3 = 1.25 × 10−4 per frame, 1.25 × 10−3 per second, 4.5 per hour. Without confirmation, 0.05 × 10 = 0.5 false alarms per second, 1800 per hour. Confirmation lowers the rate by a factor of 400 and delays a confirmed detection by two frames, 0.2 s. If the real object is detected in a frame with probability 0.8, all three of the first three frames succeed with probability 0.83 = 0.512, so the object is often confirmed a few frames later than that. All of this assumes the frames are independent.
3. A mix hides the worst case. The figure shows recall by condition of 0.78 (day), 0.48 (dusk), 0.56 (rain) and 0.52 (clutter). If the robot spends 70% of its time in day conditions and 10% in each of the others, the mix recall is 0.7 × 0.78 + 0.1 × (0.48 + 0.56 + 0.52) = 0.546 + 0.156 = 0.702, which looks fine. The plain mean of the four is 0.585, and the worst is 0.48. A requirement of “recall at least 0.6 in every condition” fails in three of the four even though the mix average passes. The right report gives the worst condition next to the average, as in Lab P6-L4.
Engineering implications and limitations
Specify error rates in operational units. “At most one false stop per hour and no more than one miss in a thousand pedestrians in range” can be tested; “95% accuracy” cannot.
Evaluate by condition. Slice the test set by lighting, weather, distance, size, occlusion and location; report each slice, its object count and the worst one (Lessons P6-T4 and P6-T5). A slice with few objects has a wide interval, so collect more data for the slices that matter.
Hold out conditions. To estimate behaviour in a new condition, keep one condition out of training and test on it. The drop is an honest estimate of the cost of shift.
Monitor in operation. You usually have no labels at run time, but you can watch proxies: the distribution of scores, the number of detections per frame, the fraction of frames with nothing detected, agreement between sensors. A change is a warning to look, not a measurement of accuracy. Label a sample periodically.
Make the system degrade safely. If the conditions look poor (low scores, dark image, rain flag), reduce speed or increase the margin instead of trusting the same threshold. The robot needs a way of knowing when its detector is out of its depth.
Fusion and tracking help, with limits. Confirming over time and combining sensors reduce false alarms (Modules 7 and 8), but only if the errors are independent; a shift that affects all sensors in the same way, such as heavy rain on a camera and a lidar, is not averaged away.
Keep the honest label. The conditions in Lab P6-L4 are simulator settings with stated effects, not recordings of real dusk or rain, and the numbers in this lesson are illustrative.
Common misconceptions
“A good detector has few false positives and few false negatives.”
The two trade against each other along the precision-recall curve, and the right balance comes from the cost of each in the application.
“Precision and recall describe the detector alone.”
Precision also depends on prevalence. The same detector has a precision of 0.67 at 10% prevalence and 0.15 at 1% in the example.
“The test accuracy is what the robot will get.”
Only if deployment looks like the test set. A mix average can hide a condition where the detector fails.
“More frames of confirmation always fix false alarms.”
Only if the errors are independent from frame to frame. A persistent false object (a poster, a reflection) is confirmed every time.
Engineering takeaways
- False positives and false negatives have task-dependent costs; the threshold should follow from them: act when p > Cfp / (Cfp + Cmiss) for a calibrated p.
- Precision = sπ / (sπ + f(1 − π)): with s = 0.9 and f = 0.05, precision falls from 0.67 to 0.15 as prevalence drops from 10% to 1%.
- Per-frame error rates are large per hour; requiring m consecutive detections cuts false alarms to q^m at a delay of m − 1 frames, if errors are independent.
- Shift comes in three kinds: covariate (inputs change), prior (frequencies change) and concept (meaning changes).
- Evaluate by condition and report the worst one beside the average; monitor proxies in operation and degrade safely.
References and further reading
Books and papers on dataset shift, robustness, calibration and error analysis. All numerical values in the examples are constructed for teaching.
- Quiñonero-Candela, J., Sugiyama, M., Schwaighofer, A. and Lawrence, N. D. (eds.) (2009). Dataset Shift in Machine Learning. MIT Press.
- Torralba, A. and Efros, A. A. (2011). Unbiased Look at Dataset Bias. CVPR.
- Hendrycks, D. and Dietterich, T. (2019). Benchmarking Neural Network Robustness to Common Corruptions and Perturbations. ICLR.
- Guo, C., Pleiss, G., Sun, Y. and Weinberger, K. Q. (2017). On Calibration of Modern Neural Networks. ICML.
- Hoiem, D., Chodpathumwan, Y. and Dai, Q. (2012). Diagnosing Error in Object Detectors. ECCV.
Knowledge check
Three conceptual questions. Write an answer, then reveal the explanation. Your answers stay in your browser.
Question 1
A miss costs 20 units and a false alarm 2. For calibrated detections, what probability threshold minimises the expected cost?
Explanation
p > Cfp / (Cfp + Cmiss) = 2 / 22 = 0.0909. Act on any detection with a probability above about 0.09. Raising the threshold would lose more in misses than it saves in false alarms.
Question 2
A detector has s = 0.95 and f = 0.02. What is its precision at a prevalence of 5%?
Explanation
precision = 0.95 × 0.05 / (0.95 × 0.05 + 0.02 × 0.95) = 0.0475 / (0.0475 + 0.019) = 0.0475 / 0.0665 = 0.714. About 71% of the detections are real.
Question 3
A tracker confirms an object after 4 consecutive detections and the per-frame false-alarm probability is 0.1. What is the chance that a false alarm is confirmed from a given start frame, and what are two reasons the real rate may be higher?
Explanation
0.1⁴ = 10⁻⁴. The real rate may be higher because (1) false alarms persist in time (the same poster or reflection is seen in every frame), so the frames are not independent, and (2) the start frame can be any of many frames, so the number of confirmations per hour is that probability times the frame rate.
What’s next
Next, Module 7: following objects through time, the step from a detection in one frame to a track.
Related content
Nothing below is required to finish this lesson.
- BeforeP6-T5: Precision, Recall and IoU
Compute IoU, precision, recall and average precision from predictions and ground truth.
- LabP6-L3: Investigate Confidence Thresholds and Missed Detections
Choose a threshold for a safety task and see the effect on misses and false alarms.
- LabP6-L4: Compare Performance Across Scene Conditions
Measure how a detector degrades across lighting, distance and clutter and report it honestly.
Get notified when the next lesson and new labs are released.
One email per new lesson or lab.