Definitionintro
Equal error rate
Also called EER, ROCCH-EER.
The error rate at the threshold where the false acceptance rate equals the false rejection rate, the usual single number for a verification system.
The equal error rate (EER) is the error rate of a detector, such as a speaker verification system, at the threshold where it makes the two kinds of error equally often. The two errors are a false acceptance (a false alarm: an impostor is accepted) and a false rejection (a miss: the true speaker is rejected). The EER lies between 0 and 1, and lower is better. It is a single number that does not depend on a choice of threshold, so it is the usual way to compare systems. It says nothing about how well a system sets its own threshold.
Definition
A trial is a pair of an enrollment and a test. A target trial has the same speaker on both sides; a nontarget trial has two different speakers. The system gives each trial a score, and it accepts the trial when the score is at least a threshold . For target scores and nontarget scores , the two error rates are
As grows, goes up from 0 to 1 and goes down from 1 to 0. The EER is the common value where they are equal.
On a finite trial list the rates move in steps of and , so usually no threshold makes them exactly equal. A page or a paper must say how it fills the gap. Two conventions are common.
- The ROC convex hull (ROCCH-EER). Plot every operating point , take the lower convex hull of these points, and return the value where the hull crosses the line . This is the convention of the BOSARIS toolkit (Brümmer and de Villiers). A point on the hull between two operating points can be reached by choosing between their two thresholds at random, so the ROCCH-EER is an error rate that a system can achieve.
- The nearest point. Take the threshold where is smallest and return . Ties need a rule; the code of this page takes the smallest such threshold.
The code computes the ROCCH-EER as follows. All rates are exact fractions.
ROCCH-EER(target scores, nontarget scores)- 1
P ← the points (P_fa(θ), P_miss(θ)) for θ at every score and at +∞ - 2
add the points (0, 1) and (1, 0) - 3
H ← the lower convex hull of P, from P_fa = 0 to the first vertex with P_miss = 0 - 4
find the edge (f₁, m₁)-(f₂, m₂) of H with m₁ ≥ f₁ and m₂ ≤ f₂ - 5
s ← (m₁ - f₁) / ((f₂ - f₁) - (m₂ - m₁)) - 6
return f₁ + s (f₂ - f₁)
After sorting the scores in time, with , the points, the hull and the crossing take time.
Four facts follow from the definition.
- Range. The ROCCH-EER is at most . The points and are operating points, so the hull lies on or below the line between them, which meets the diagonal at . A system with reversed scores has a nearest-point EER above but a ROCCH-EER of exactly .
- Only the order counts. Both conventions depend only on the order of the scores. A strictly increasing map of all scores, such as or , does not change the EER. So the EER does not measure calibration.
- The worst minimum cost (a theorem). Let , the minimum detection cost with a target prior and unit costs. Then . Proof: a linear function has the same minimum over a finite point set as over its convex hull. The point on the hull gives the cost for every , so . The edge of L4 lies on a supporting line of the convex hull; take , which makes the cost constant along that line. Every point of the hull then has a cost of at least , so .
- Gaussian scores. If the target and nontarget scores are normal with equal variance and means standard deviations apart, the threshold halfway between the means gives , where is the standard normal distribution function. For this is .
Examples and non-examples
A hand-made trial list. The target scores are and the nontarget scores are . The operating points are:
| 0.1 | 0.3 | 0.35 | 0.4 | 0.45 | 0.5 | 0.6 | 0.7 | 0.8 | 0.9 | ||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 4/5 | 4/5 | 3/5 | 2/5 | 2/5 | 1/5 | 1/5 | 0 | 0 | 0 | |
| 0 | 0 | 1/5 | 1/5 | 1/5 | 2/5 | 2/5 | 3/5 | 3/5 | 4/5 | 1 |
At the two rates are both , so the nearest-point EER is . The lower hull has the vertices , and . Its first edge crosses the diagonal at , so the ROCCH-EER is . A system reaches this rate by using on a random quarter of the trials and on the rest: and . As the theorem says, at .
Other cases:
- A tie. For target scores and nontarget scores , the thresholds and both give , with means and . The ROCCH-EER is . On small lists the convention changes the result a lot.
- Perfect separation. If every target score is above every nontarget score, a threshold between them gives no errors, and the EER is 0.
- Non-example: the error rate at a fixed threshold. A system that runs at has an actual miss rate and false alarm rate, and they are usually not equal. The EER describes a threshold chosen afterward on the test data itself, so no deployed system reaches it unless its threshold happens to be right.
- Non-example: the half total error rate. at a threshold fixed in advance is another number. It equals the EER only at the equal error threshold.
Related definitions
- The DET curve (Martin et al. 1997) plots against on normal deviate scales, where Gaussian scores give straight lines. The EER is the point where the curve meets the diagonal. The ROC curve is the same set of operating points plotted as against .
- The detection cost function is the measure of the NIST speaker recognition evaluations. For scores that are calibrated log likelihood ratios, the Bayes threshold is (BOSARIS, Section 2.2). For example, , and give . Unlike the EER, the actual cost at this threshold measures calibration.
- The EER is a point on the curve whose area is the ROC AUC; two systems with the same EER can have different AUCs.
- In speech recognition, the word error rate plays the role that the EER plays in verification, but it counts edits and is not a detection measure.
Code
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/equal-error-rate/. The authors are listed in prov/QFSA7K.jsonl.
"""Equal error rate of a detector on a finite list of trials.
A trial is accepted when its score is at least the threshold t. For a list of
target scores and a list of nontarget scores,
Pmiss(t) = (number of target scores < t) / (number of targets),
Pfa(t) = (number of nontarget scores >= t) / (number of nontargets).
On a finite list the two rates move in steps, so they are rarely equal at any
threshold. eer_rocch follows Brummer and de Villiers (BOSARIS): it takes the
lower convex hull of the operating points (the ROC convex hull) and returns
the rate where the hull crosses the line Pmiss = Pfa. eer_nearest returns the
mean of the two rates at the threshold where they are closest. All rates are
exact fractions.
"""
from bisect import bisect_left
from fractions import Fraction
from typing import List, Sequence, Tuple
Point = Tuple[Fraction, Fraction] # (Pfa, Pmiss)
def operating_points(targets: Sequence[float], nontargets: Sequence[float]) -> List[Tuple[float, Fraction, Fraction]]:
"""Return (t, Pfa, Pmiss) for t at every distinct score and at +infinity, in increasing t."""
if not targets or not nontargets:
raise ValueError("need at least one target and one nontarget score")
tar, non = sorted(targets), sorted(nontargets)
nt, nn = len(tar), len(non)
out = []
for t in sorted(set(tar) | set(non)) + [float("inf")]:
pmiss = Fraction(bisect_left(tar, t), nt)
pfa = Fraction(nn - bisect_left(non, t), nn)
out.append((t, pfa, pmiss))
return out
def cross(o: Point, a: Point, b: Point) -> Fraction:
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0])
def lower_hull(points: Sequence[Point]) -> List[Point]:
"""Return the lower convex hull of the points, from the smallest Pfa to the largest."""
hull: List[Point] = []
for p in sorted(set(points)):
while len(hull) >= 2 and cross(hull[-2], hull[-1], p) <= 0:
hull.pop()
hull.append(p)
return hull
def rocch(targets: Sequence[float], nontargets: Sequence[float]) -> List[Point]:
"""Return the vertices (Pfa, Pmiss) of the ROC convex hull."""
pts = [(pfa, pmiss) for _, pfa, pmiss in operating_points(targets, nontargets)] # @line L1
pts += [(Fraction(0), Fraction(1)), (Fraction(1), Fraction(0))] # @line L2
# Keep only the vertices from (0, 1) down to the first point with Pmiss = 0.
hull = lower_hull(pts) # @line L3
k = next(i for i, p in enumerate(hull) if p[1] == 0)
return hull[: k + 1]
def eer_rocch(targets: Sequence[float], nontargets: Sequence[float]) -> Fraction:
"""Return the equal error rate of the ROC convex hull."""
hull = rocch(targets, nontargets)
if len(hull) == 1: # the point (0, 0): the scores separate the classes
return Fraction(0)
for (f1, m1), (f2, m2) in zip(hull, hull[1:]):
if m1 >= f1 and m2 <= f2: # @line L4
df, dm = f2 - f1, m2 - m1
s = (m1 - f1) / (df - dm) # @line L5
return f1 + s * df # @line L6
raise AssertionError("the hull always crosses Pmiss = Pfa")
def eer_nearest(targets: Sequence[float], nontargets: Sequence[float]) -> Fraction:
"""Return (Pfa + Pmiss) / 2 at the threshold where |Pfa - Pmiss| is smallest (the first such threshold)."""
best = min(operating_points(targets, nontargets), key=lambda r: abs(r[1] - r[2]))
return (best[1] + best[2]) / 2
def min_dcf(targets: Sequence[float], nontargets: Sequence[float], p_target: Fraction,
c_miss: Fraction = Fraction(1), c_fa: Fraction = Fraction(1)) -> Fraction:
"""Return min over thresholds of c_miss p_target Pmiss + c_fa (1 - p_target) Pfa."""
return min(c_miss * p_target * pm + c_fa * (1 - p_target) * pf
for _, pf, pm in operating_points(targets, nontargets))
test_equal_error_rate.py 100 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/equal-error-rate/. The authors are listed in prov/QFSA7K.jsonl.
import math
import os
import random
import sys
from fractions import Fraction as F
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import pytest
from equal_error_rate import eer_nearest, eer_rocch, min_dcf, operating_points, rocch
TAR = [0.9, 0.8, 0.6, 0.45, 0.3]
NON = [0.7, 0.5, 0.4, 0.35, 0.1]
def test_page_example():
pts = [(pf, pm) for _, pf, pm in operating_points(TAR, NON)]
assert pts == [(F(1), F(0)), (F(4, 5), F(0)), (F(4, 5), F(1, 5)), (F(3, 5), F(1, 5)), (F(2, 5), F(1, 5)),
(F(2, 5), F(2, 5)), (F(1, 5), F(2, 5)), (F(1, 5), F(3, 5)), (F(0), F(3, 5)), (F(0), F(4, 5)),
(F(0), F(1))]
assert rocch(TAR, NON) == [(F(0), F(3, 5)), (F(2, 5), F(1, 5)), (F(4, 5), F(0))]
assert eer_rocch(TAR, NON) == F(3, 10)
assert eer_nearest(TAR, NON) == F(2, 5)
assert min_dcf(TAR, NON, F(1, 2)) == F(3, 10)
def test_conventions_differ_on_a_tie():
tar = [0.9, 0.8, 0.7, 0.4]
non = [0.75, 0.5, 0.3, 0.2, 0.1, 0.05]
assert eer_rocch(tar, non) == F(1, 5)
assert eer_nearest(tar, non) == F(7, 24)
def test_extremes():
assert eer_rocch([2.0, 3.0], [0.0, 1.0]) == 0
assert eer_rocch([0.5], [0.5]) == F(1, 2)
rng = random.Random(5)
tar = [rng.uniform(0.0, 1.0) for _ in range(30)]
non = [rng.uniform(2.0, 3.0) for _ in range(40)]
# Reversed scores: the hull is the chance line, so the hull EER is 1/2.
assert eer_rocch(tar, non) == F(1, 2)
assert eer_nearest(tar, non) > F(1, 2)
with pytest.raises(ValueError):
eer_rocch([], [1.0])
def test_rocch_eer_is_max_of_min_dcf():
rng = random.Random(7)
for _ in range(20):
tar = [round(rng.gauss(1.0, 1.0), 2) for _ in range(rng.randint(1, 15))]
non = [round(rng.gauss(0.0, 1.0), 2) for _ in range(rng.randint(1, 15))]
eer = eer_rocch(tar, non)
for k in range(0, 41):
assert min_dcf(tar, non, F(k, 40)) <= eer
hull = rocch(tar, non)
if len(hull) == 1:
assert eer == 0
continue
for (f1, m1), (f2, m2) in zip(hull, hull[1:]):
if m1 >= f1 and m2 <= f2:
p = (f2 - f1) / ((f2 - f1) + (m1 - m2))
assert min_dcf(tar, non, p) == eer
break
def test_invariant_under_monotone_maps():
rng = random.Random(11)
tar = [rng.gauss(1.0, 1.0) for _ in range(25)]
non = [rng.gauss(0.0, 1.0) for _ in range(35)]
e = eer_rocch(tar, non)
assert eer_rocch([3.0 * s + 1.0 for s in tar], [3.0 * s + 1.0 for s in non]) == e
assert eer_rocch([math.exp(s) for s in tar], [math.exp(s) for s in non]) == e
assert eer_nearest([math.exp(s) for s in tar], [math.exp(s) for s in non]) == eer_nearest(tar, non)
def test_hull_never_above_steps():
rng = random.Random(13)
tar = [rng.gauss(0.8, 1.0) for _ in range(20)]
non = [rng.gauss(0.0, 1.0) for _ in range(20)]
assert eer_rocch(tar, non) <= eer_nearest(tar, non) + F(1, 20)
hull = rocch(tar, non)
for _, pf, pm in operating_points(tar, non):
# Every operating point lies on or above the hull.
for (f1, m1), (f2, m2) in zip(hull, hull[1:]):
if f1 <= pf <= f2:
assert pm >= m1 + (m2 - m1) * (pf - f1) / (f2 - f1)
def test_gaussian_scores():
rng = random.Random(17)
tar = [rng.gauss(2.0, 1.0) for _ in range(3000)]
non = [rng.gauss(0.0, 1.0) for _ in range(3000)]
# Equal variances and d' = 2 give the EER Phi(-1) = 0.158655.
phi = 0.5 * math.erfc(1.0 / math.sqrt(2.0))
assert abs(float(eer_rocch(tar, non)) - phi) < 0.02
assert abs(float(eer_nearest(tar, non)) - phi) < 0.02
References
- Niko Brümmer and Edward de Villiers, The BOSARIS toolkit, theory, algorithms and code for surviving the new DCF, NIST SRE 2011 workshop, arXiv 1304.2865, 2013, Section 2.2 (the Bayes threshold, equations 3 to 6) and Section 2.6.2 (the ROCCH-EER, equation 26)
- Alvin Martin, George Doddington, Terri Kamm, Mark Ordowski and Mark Przybocki, The DET curve in assessment of detection task performance, Eurospeech 1997, the DET curve with normal deviate scales and the operating points on it
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag QFSA7K Edit this page History Report an error Markdown