Bayes Classifier
Classification assigns an input to one of discrete classes, labeled . The problem is binary classification when and multi-class classification when . Binary problems usually label the classes and . A classifier splits the input space into decision regions . The surfaces between the regions are the decision boundaries. For a linear classifier each boundary is a -dimensional hyperplane: a point when , a line when and a plane when . A dataset is linearly separable when some hyperplane puts all points of each class on their own side.
A classifier is scored by its 0-1 risk, the probability that it predicts the wrong class:
Here is drawn from the joint distribution of inputs and labels. The indicator equals when its condition holds and otherwise. The Bayes classifier picks the class with the largest posterior probability. Bayes’ rule writes that posterior with class densities and priors:
Here is the class-conditional density of class , and is its prior. No classifier has a lower 0-1 risk than . The risk of is the Bayes error rate,
where the expectation runs over the input distribution. is positive whenever the classes overlap.Unequal error costs move the binary threshold. Let be the cost of a false alarm and the cost of a missed positive. The rule with the lowest expected cost predicts class when
Equal costs give the threshold , which is the Bayes classifier.The true posterior is unknown, so practical classifiers take one of three approaches (Bishop, PRML, ch. 4):
- Discriminant functions map an input straight to a class, with no probabilities. Examples are linear discriminants, the perceptron and support vector machines.
- Generative models fit and , then apply Bayes’ rule. Examples are naive Bayes and the Gaussian models LDA and QDA in 4.2. Linear Discriminants.
- Discriminative models fit directly and never model how arises. Examples are logistic regression and softmax regression, both trained by minimizing cross-entropy.
Intuition
Picture healthy and faulty machines whose vibration readings overlap. Suppose that at one reading, 80% of machines are faulty. Any rule must guess there. Guessing “faulty” is wrong 20% of the time, and guessing “healthy” is wrong 80% of the time. The Bayes classifier takes the more probable class at every input. It therefore makes the smallest possible error at each input. It carries Bayes’ name because it computes the posterior with Bayes’ rule, from the class densities and the class frequencies.
Nobody knows the true distribution, so the Bayes classifier serves as a benchmark. Each practical method estimates some part of it from data. A generative model estimates the densities and the priors. A discriminative model estimates the posterior. A discriminant function learns only the boundary. The Bayes error is the error that remains with perfect knowledge. A better model can remove the part of its error above . No model can reach an error below .
Each curve is a class prior times its density. The Bayes rule predicts the class with the higher curve, and the gray area is the Bayes error. As the prior grows, the boundary moves and the error falls.
\usepackage{tikz}
\usetikzlibrary{animations, arrows.meta}
\begin{document}
\definecolor{hot}{HTML}{D9483B}
\definecolor{cold}{HTML}{2F80ED}
\definecolor{mid}{HTML}{8A8A8A}
\begin{tikzpicture}[font=\small, >={Stealth[length=2.2mm]}, xshift=0.3cm]
\draw[->] (-0.10,0) -- (9.30,0) node[right] {$x$};
\draw (0.50,0) -- (0.50,-0.1) node[below] {\footnotesize $-3$};
\draw (1.50,0) -- (1.50,-0.1) node[below] {\footnotesize $-2$};
\draw (2.50,0) -- (2.50,-0.1) node[below] {\footnotesize $-1$};
\draw (3.50,0) -- (3.50,-0.1) node[below] {\footnotesize $0$};
\draw (4.50,0) -- (4.50,-0.1) node[below] {\footnotesize $1$};
\draw (5.50,0) -- (5.50,-0.1) node[below] {\footnotesize $2$};
\draw (6.50,0) -- (6.50,-0.1) node[below] {\footnotesize $3$};
\draw (7.50,0) -- (7.50,-0.1) node[below] {\footnotesize $4$};
\draw (8.50,0) -- (8.50,-0.1) node[below] {\footnotesize $5$};
\node[anchor=west] at (10.1,0.6) {\footnotesize Bayes error $= \int \min_k \pi_k\, p(x\mid k)\, dx$};
\node[anchor=west] at (10.1,0.05) {\footnotesize $p(x\mid k) = \mathcal N(\mu_k, 1)$, \ $\mu_0 = 0$, $\mu_1 = 2$};
\begin{scope}[animate = {myself: = {:visible = {0s = "true", 2.6s = "false", 13.55s = "false", repeats}}}]
\draw[cold, very thick] (0.00,0.00) -- (0.15,0.01) -- (0.30,0.01) -- (0.45,0.02) -- (0.60,0.03) -- (0.75,0.05) -- (0.90,0.07) -- (1.05,0.11) -- (1.20,0.16) -- (1.35,0.22) -- (1.50,0.30) -- (1.65,0.40) -- (1.80,0.52) -- (1.95,0.66) -- (2.10,0.82) -- (2.25,1.00) -- (2.40,1.20) -- (2.55,1.40) -- (2.70,1.59) -- (2.85,1.78) -- (3.00,1.94) -- (3.15,2.06) -- (3.30,2.15) -- (3.45,2.19) -- (3.60,2.18) -- (3.75,2.13) -- (3.90,2.03) -- (4.05,1.89) -- (4.20,1.72) -- (4.35,1.53) -- (4.50,1.33) -- (4.65,1.13) -- (4.80,0.94) -- (4.95,0.77) -- (5.10,0.61) -- (5.25,0.47) -- (5.40,0.36) -- (5.55,0.27) -- (5.70,0.20) -- (5.85,0.14) -- (6.00,0.10) -- (6.15,0.07) -- (6.30,0.04) -- (6.45,0.03) -- (6.60,0.02) -- (6.75,0.01) -- (6.90,0.01) -- (7.05,0.00) -- (7.20,0.00) -- (7.35,0.00) -- (7.50,0.00) -- (7.65,0.00) -- (7.80,0.00) -- (7.95,0.00) -- (8.10,0.00) -- (8.25,0.00) -- (8.40,0.00) -- (8.55,0.00) -- (8.70,0.00) -- (8.85,0.00) -- (9.00,0.00);
\draw[hot, very thick] (0.00,0.00) -- (0.15,0.00) -- (0.30,0.00) -- (0.45,0.00) -- (0.60,0.00) -- (0.75,0.00) -- (0.90,0.00) -- (1.05,0.00) -- (1.20,0.00) -- (1.35,0.00) -- (1.50,0.00) -- (1.65,0.00) -- (1.80,0.00) -- (1.95,0.00) -- (2.10,0.01) -- (2.25,0.01) -- (2.40,0.02) -- (2.55,0.03) -- (2.70,0.04) -- (2.85,0.07) -- (3.00,0.10) -- (3.15,0.14) -- (3.30,0.20) -- (3.45,0.27) -- (3.60,0.36) -- (3.75,0.47) -- (3.90,0.61) -- (4.05,0.77) -- (4.20,0.94) -- (4.35,1.13) -- (4.50,1.33) -- (4.65,1.53) -- (4.80,1.72) -- (4.95,1.89) -- (5.10,2.03) -- (5.25,2.13) -- (5.40,2.18) -- (5.55,2.19) -- (5.70,2.15) -- (5.85,2.06) -- (6.00,1.94) -- (6.15,1.78) -- (6.30,1.59) -- (6.45,1.40) -- (6.60,1.20) -- (6.75,1.00) -- (6.90,0.82) -- (7.05,0.66) -- (7.20,0.52) -- (7.35,0.40) -- (7.50,0.30) -- (7.65,0.22) -- (7.80,0.16) -- (7.95,0.11) -- (8.10,0.07) -- (8.25,0.05) -- (8.40,0.03) -- (8.55,0.02) -- (8.70,0.01) -- (8.85,0.01) -- (9.00,0.00);
\node[anchor=south east, inner sep=1pt] at (2.35,1.23) {$\pi_0\, p(x\mid 0)$};
\node[anchor=south west, inner sep=1pt] at (6.65,1.23) {$\pi_1\, p(x\mid 1)$};
\node[anchor=west] at (10.1,3.5) {$\pi_1 = 0.50, \ \pi_0 = 0.50$};
\node[anchor=west] at (-0.3,-1.75) {Each curve is a class prior times its density. The priors start equal.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 2.6s = "true", 5.4s = "false", 13.55s = "false", repeats}}}]
\draw[cold, very thick] (0.00,0.00) -- (0.15,0.01) -- (0.30,0.01) -- (0.45,0.02) -- (0.60,0.03) -- (0.75,0.05) -- (0.90,0.07) -- (1.05,0.11) -- (1.20,0.16) -- (1.35,0.22) -- (1.50,0.30) -- (1.65,0.40) -- (1.80,0.52) -- (1.95,0.66) -- (2.10,0.82) -- (2.25,1.00) -- (2.40,1.20) -- (2.55,1.40) -- (2.70,1.59) -- (2.85,1.78) -- (3.00,1.94) -- (3.15,2.06) -- (3.30,2.15) -- (3.45,2.19) -- (3.60,2.18) -- (3.75,2.13) -- (3.90,2.03) -- (4.05,1.89) -- (4.20,1.72) -- (4.35,1.53) -- (4.50,1.33) -- (4.65,1.13) -- (4.80,0.94) -- (4.95,0.77) -- (5.10,0.61) -- (5.25,0.47) -- (5.40,0.36) -- (5.55,0.27) -- (5.70,0.20) -- (5.85,0.14) -- (6.00,0.10) -- (6.15,0.07) -- (6.30,0.04) -- (6.45,0.03) -- (6.60,0.02) -- (6.75,0.01) -- (6.90,0.01) -- (7.05,0.00) -- (7.20,0.00) -- (7.35,0.00) -- (7.50,0.00) -- (7.65,0.00) -- (7.80,0.00) -- (7.95,0.00) -- (8.10,0.00) -- (8.25,0.00) -- (8.40,0.00) -- (8.55,0.00) -- (8.70,0.00) -- (8.85,0.00) -- (9.00,0.00);
\draw[hot, very thick] (0.00,0.00) -- (0.15,0.00) -- (0.30,0.00) -- (0.45,0.00) -- (0.60,0.00) -- (0.75,0.00) -- (0.90,0.00) -- (1.05,0.00) -- (1.20,0.00) -- (1.35,0.00) -- (1.50,0.00) -- (1.65,0.00) -- (1.80,0.00) -- (1.95,0.00) -- (2.10,0.01) -- (2.25,0.01) -- (2.40,0.02) -- (2.55,0.03) -- (2.70,0.04) -- (2.85,0.07) -- (3.00,0.10) -- (3.15,0.14) -- (3.30,0.20) -- (3.45,0.27) -- (3.60,0.36) -- (3.75,0.47) -- (3.90,0.61) -- (4.05,0.77) -- (4.20,0.94) -- (4.35,1.13) -- (4.50,1.33) -- (4.65,1.53) -- (4.80,1.72) -- (4.95,1.89) -- (5.10,2.03) -- (5.25,2.13) -- (5.40,2.18) -- (5.55,2.19) -- (5.70,2.15) -- (5.85,2.06) -- (6.00,1.94) -- (6.15,1.78) -- (6.30,1.59) -- (6.45,1.40) -- (6.60,1.20) -- (6.75,1.00) -- (6.90,0.82) -- (7.05,0.66) -- (7.20,0.52) -- (7.35,0.40) -- (7.50,0.30) -- (7.65,0.22) -- (7.80,0.16) -- (7.95,0.11) -- (8.10,0.07) -- (8.25,0.05) -- (8.40,0.03) -- (8.55,0.02) -- (8.70,0.01) -- (8.85,0.01) -- (9.00,0.00);
\node[anchor=south east, inner sep=1pt] at (2.35,1.23) {$\pi_0\, p(x\mid 0)$};
\node[anchor=south west, inner sep=1pt] at (6.65,1.23) {$\pi_1\, p(x\mid 1)$};
\node[anchor=west] at (10.1,3.5) {$\pi_1 = 0.50, \ \pi_0 = 0.50$};
\draw[thick] (4.50,0) -- (4.50,2.54);
\node[anchor=east] at (4.42,-0.95) {\footnotesize predict $0$ $\leftarrow$};
\node[anchor=west] at (4.58,-0.95) {\footnotesize $\rightarrow$ predict $1$};
\node[anchor=west] at (10.1,2.8) {boundary $x^* = 1.00$};
\node[anchor=west] at (-0.3,-1.75) {The Bayes rule predicts the class with the higher curve. The boundary is where they cross.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 5.4s = "true", 8.4s = "false", 13.55s = "false", repeats}}}]
\fill[mid] (0.00,0) -- (0.00,0.00) -- (0.15,0.00) -- (0.30,0.00) -- (0.45,0.00) -- (0.60,0.00) -- (0.75,0.00) -- (0.90,0.00) -- (1.05,0.00) -- (1.20,0.00) -- (1.35,0.00) -- (1.50,0.00) -- (1.65,0.00) -- (1.80,0.00) -- (1.95,0.00) -- (2.10,0.01) -- (2.25,0.01) -- (2.40,0.02) -- (2.55,0.03) -- (2.70,0.04) -- (2.85,0.07) -- (3.00,0.10) -- (3.15,0.14) -- (3.30,0.20) -- (3.45,0.27) -- (3.60,0.36) -- (3.75,0.47) -- (3.90,0.61) -- (4.05,0.77) -- (4.20,0.94) -- (4.35,1.13) -- (4.50,1.33) -- (4.50,1.33) -- (4.65,1.13) -- (4.80,0.94) -- (4.95,0.77) -- (5.10,0.61) -- (5.25,0.47) -- (5.40,0.36) -- (5.55,0.27) -- (5.70,0.20) -- (5.85,0.14) -- (6.00,0.10) -- (6.15,0.07) -- (6.30,0.04) -- (6.45,0.03) -- (6.60,0.02) -- (6.75,0.01) -- (6.90,0.01) -- (7.05,0.00) -- (7.20,0.00) -- (7.35,0.00) -- (7.50,0.00) -- (7.65,0.00) -- (7.80,0.00) -- (7.95,0.00) -- (8.10,0.00) -- (8.25,0.00) -- (8.40,0.00) -- (8.55,0.00) -- (8.70,0.00) -- (8.85,0.00) -- (9.00,0.00) -- (9.00,0) -- cycle;
\draw[cold, very thick] (0.00,0.00) -- (0.15,0.01) -- (0.30,0.01) -- (0.45,0.02) -- (0.60,0.03) -- (0.75,0.05) -- (0.90,0.07) -- (1.05,0.11) -- (1.20,0.16) -- (1.35,0.22) -- (1.50,0.30) -- (1.65,0.40) -- (1.80,0.52) -- (1.95,0.66) -- (2.10,0.82) -- (2.25,1.00) -- (2.40,1.20) -- (2.55,1.40) -- (2.70,1.59) -- (2.85,1.78) -- (3.00,1.94) -- (3.15,2.06) -- (3.30,2.15) -- (3.45,2.19) -- (3.60,2.18) -- (3.75,2.13) -- (3.90,2.03) -- (4.05,1.89) -- (4.20,1.72) -- (4.35,1.53) -- (4.50,1.33) -- (4.65,1.13) -- (4.80,0.94) -- (4.95,0.77) -- (5.10,0.61) -- (5.25,0.47) -- (5.40,0.36) -- (5.55,0.27) -- (5.70,0.20) -- (5.85,0.14) -- (6.00,0.10) -- (6.15,0.07) -- (6.30,0.04) -- (6.45,0.03) -- (6.60,0.02) -- (6.75,0.01) -- (6.90,0.01) -- (7.05,0.00) -- (7.20,0.00) -- (7.35,0.00) -- (7.50,0.00) -- (7.65,0.00) -- (7.80,0.00) -- (7.95,0.00) -- (8.10,0.00) -- (8.25,0.00) -- (8.40,0.00) -- (8.55,0.00) -- (8.70,0.00) -- (8.85,0.00) -- (9.00,0.00);
\draw[hot, very thick] (0.00,0.00) -- (0.15,0.00) -- (0.30,0.00) -- (0.45,0.00) -- (0.60,0.00) -- (0.75,0.00) -- (0.90,0.00) -- (1.05,0.00) -- (1.20,0.00) -- (1.35,0.00) -- (1.50,0.00) -- (1.65,0.00) -- (1.80,0.00) -- (1.95,0.00) -- (2.10,0.01) -- (2.25,0.01) -- (2.40,0.02) -- (2.55,0.03) -- (2.70,0.04) -- (2.85,0.07) -- (3.00,0.10) -- (3.15,0.14) -- (3.30,0.20) -- (3.45,0.27) -- (3.60,0.36) -- (3.75,0.47) -- (3.90,0.61) -- (4.05,0.77) -- (4.20,0.94) -- (4.35,1.13) -- (4.50,1.33) -- (4.65,1.53) -- (4.80,1.72) -- (4.95,1.89) -- (5.10,2.03) -- (5.25,2.13) -- (5.40,2.18) -- (5.55,2.19) -- (5.70,2.15) -- (5.85,2.06) -- (6.00,1.94) -- (6.15,1.78) -- (6.30,1.59) -- (6.45,1.40) -- (6.60,1.20) -- (6.75,1.00) -- (6.90,0.82) -- (7.05,0.66) -- (7.20,0.52) -- (7.35,0.40) -- (7.50,0.30) -- (7.65,0.22) -- (7.80,0.16) -- (7.95,0.11) -- (8.10,0.07) -- (8.25,0.05) -- (8.40,0.03) -- (8.55,0.02) -- (8.70,0.01) -- (8.85,0.01) -- (9.00,0.00);
\node[anchor=south east, inner sep=1pt] at (2.35,1.23) {$\pi_0\, p(x\mid 0)$};
\node[anchor=south west, inner sep=1pt] at (6.65,1.23) {$\pi_1\, p(x\mid 1)$};
\node[anchor=west] at (10.1,3.5) {$\pi_1 = 0.50, \ \pi_0 = 0.50$};
\draw[thick] (4.50,0) -- (4.50,2.54);
\node[anchor=east] at (4.42,-0.95) {\footnotesize predict $0$ $\leftarrow$};
\node[anchor=west] at (4.58,-0.95) {\footnotesize $\rightarrow$ predict $1$};
\node[anchor=west] at (10.1,2.8) {boundary $x^* = 1.00$};
\node[anchor=west] at (10.1,2.1) {Bayes error $= 0.159$};
\node[anchor=west] at (10.1,1.5) {\footnotesize $= 0.079$ (class $0$) ${}+ 0.079$ (class $1$)};
\node[anchor=west] at (-0.3,-1.75) {The gray area under the lower curve is the Bayes error. No classifier has a lower error.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 8.4s = "true", 8.65s = "false", 13.55s = "false", repeats}}}]
\fill[mid] (0.00,0) -- (0.00,0.00) -- (0.15,0.00) -- (0.30,0.00) -- (0.45,0.00) -- (0.60,0.00) -- (0.75,0.00) -- (0.90,0.00) -- (1.05,0.00) -- (1.20,0.00) -- (1.35,0.00) -- (1.50,0.00) -- (1.65,0.00) -- (1.80,0.00) -- (1.95,0.00) -- (2.10,0.01) -- (2.25,0.01) -- (2.40,0.02) -- (2.55,0.03) -- (2.70,0.04) -- (2.85,0.07) -- (3.00,0.10) -- (3.15,0.14) -- (3.30,0.20) -- (3.45,0.28) -- (3.60,0.37) -- (3.75,0.49) -- (3.90,0.63) -- (4.05,0.79) -- (4.20,0.97) -- (4.35,1.17) -- (4.47,1.33) -- (4.50,1.29) -- (4.65,1.10) -- (4.80,0.91) -- (4.95,0.74) -- (5.10,0.59) -- (5.25,0.46) -- (5.40,0.35) -- (5.55,0.26) -- (5.70,0.19) -- (5.85,0.13) -- (6.00,0.09) -- (6.15,0.06) -- (6.30,0.04) -- (6.45,0.03) -- (6.60,0.02) -- (6.75,0.01) -- (6.90,0.01) -- (7.05,0.00) -- (7.20,0.00) -- (7.35,0.00) -- (7.50,0.00) -- (7.65,0.00) -- (7.80,0.00) -- (7.95,0.00) -- (8.10,0.00) -- (8.25,0.00) -- (8.40,0.00) -- (8.55,0.00) -- (8.70,0.00) -- (8.85,0.00) -- (9.00,0.00) -- (9.00,0) -- cycle;
\draw[cold, very thick] (0.00,0.00) -- (0.15,0.01) -- (0.30,0.01) -- (0.45,0.02) -- (0.60,0.03) -- (0.75,0.05) -- (0.90,0.07) -- (1.05,0.11) -- (1.20,0.15) -- (1.35,0.21) -- (1.50,0.29) -- (1.65,0.38) -- (1.80,0.50) -- (1.95,0.64) -- (2.10,0.80) -- (2.25,0.97) -- (2.40,1.16) -- (2.55,1.36) -- (2.70,1.55) -- (2.85,1.72) -- (3.00,1.88) -- (3.15,2.00) -- (3.30,2.09) -- (3.45,2.13) -- (3.60,2.12) -- (3.75,2.06) -- (3.90,1.96) -- (4.05,1.83) -- (4.20,1.67) -- (4.35,1.48) -- (4.50,1.29) -- (4.65,1.10) -- (4.80,0.91) -- (4.95,0.74) -- (5.10,0.59) -- (5.25,0.46) -- (5.40,0.35) -- (5.55,0.26) -- (5.70,0.19) -- (5.85,0.13) -- (6.00,0.09) -- (6.15,0.06) -- (6.30,0.04) -- (6.45,0.03) -- (6.60,0.02) -- (6.75,0.01) -- (6.90,0.01) -- (7.05,0.00) -- (7.20,0.00) -- (7.35,0.00) -- (7.50,0.00) -- (7.65,0.00) -- (7.80,0.00) -- (7.95,0.00) -- (8.10,0.00) -- (8.25,0.00) -- (8.40,0.00) -- (8.55,0.00) -- (8.70,0.00) -- (8.85,0.00) -- (9.00,0.00);
\draw[hot, very thick] (0.00,0.00) -- (0.15,0.00) -- (0.30,0.00) -- (0.45,0.00) -- (0.60,0.00) -- (0.75,0.00) -- (0.90,0.00) -- (1.05,0.00) -- (1.20,0.00) -- (1.35,0.00) -- (1.50,0.00) -- (1.65,0.00) -- (1.80,0.00) -- (1.95,0.00) -- (2.10,0.01) -- (2.25,0.01) -- (2.40,0.02) -- (2.55,0.03) -- (2.70,0.04) -- (2.85,0.07) -- (3.00,0.10) -- (3.15,0.14) -- (3.30,0.20) -- (3.45,0.28) -- (3.60,0.37) -- (3.75,0.49) -- (3.90,0.63) -- (4.05,0.79) -- (4.20,0.97) -- (4.35,1.17) -- (4.50,1.37) -- (4.65,1.57) -- (4.80,1.77) -- (4.95,1.94) -- (5.10,2.09) -- (5.25,2.19) -- (5.40,2.25) -- (5.55,2.26) -- (5.70,2.22) -- (5.85,2.13) -- (6.00,1.99) -- (6.15,1.83) -- (6.30,1.64) -- (6.45,1.44) -- (6.60,1.23) -- (6.75,1.03) -- (6.90,0.85) -- (7.05,0.68) -- (7.20,0.53) -- (7.35,0.41) -- (7.50,0.31) -- (7.65,0.22) -- (7.80,0.16) -- (7.95,0.11) -- (8.10,0.08) -- (8.25,0.05) -- (8.40,0.03) -- (8.55,0.02) -- (8.70,0.01) -- (8.85,0.01) -- (9.00,0.00);
\node[anchor=south east, inner sep=1pt] at (2.35,1.20) {$\pi_0\, p(x\mid 0)$};
\node[anchor=south west, inner sep=1pt] at (6.65,1.27) {$\pi_1\, p(x\mid 1)$};
\node[anchor=west] at (10.1,3.5) {$\pi_1 = 0.52, \ \pi_0 = 0.48$};
\draw[thick] (4.47,0) -- (4.47,2.61);
\node[anchor=east] at (4.39,-0.95) {\footnotesize predict $0$ $\leftarrow$};
\node[anchor=west] at (4.55,-0.95) {\footnotesize $\rightarrow$ predict $1$};
\node[anchor=west] at (10.1,2.8) {boundary $x^* = 0.97$};
\node[anchor=west] at (10.1,2.1) {Bayes error $= 0.159$};
\node[anchor=west] at (10.1,1.5) {\footnotesize $= 0.081$ (class $0$) ${}+ 0.078$ (class $1$)};
\node[anchor=west] at (-0.3,-1.75) {The prior $\pi_1$ grows. The red curve rises and the boundary moves toward the blue class.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 8.65s = "true", 8.9s = "false", 13.55s = "false", repeats}}}]
\fill[mid] (0.00,0) -- (0.00,0.00) -- (0.15,0.00) -- (0.30,0.00) -- (0.45,0.00) -- (0.60,0.00) -- (0.75,0.00) -- (0.90,0.00) -- (1.05,0.00) -- (1.20,0.00) -- (1.35,0.00) -- (1.50,0.00) -- (1.65,0.00) -- (1.80,0.00) -- (1.95,0.00) -- (2.10,0.01) -- (2.25,0.01) -- (2.40,0.02) -- (2.55,0.03) -- (2.70,0.05) -- (2.85,0.07) -- (3.00,0.11) -- (3.15,0.15) -- (3.30,0.22) -- (3.45,0.30) -- (3.60,0.40) -- (3.75,0.53) -- (3.90,0.68) -- (4.05,0.85) -- (4.20,1.05) -- (4.35,1.26) -- (4.39,1.31) -- (4.50,1.19) -- (4.65,1.01) -- (4.80,0.84) -- (4.95,0.68) -- (5.10,0.54) -- (5.25,0.42) -- (5.40,0.32) -- (5.55,0.24) -- (5.70,0.17) -- (5.85,0.12) -- (6.00,0.09) -- (6.15,0.06) -- (6.30,0.04) -- (6.45,0.03) -- (6.60,0.02) -- (6.75,0.01) -- (6.90,0.01) -- (7.05,0.00) -- (7.20,0.00) -- (7.35,0.00) -- (7.50,0.00) -- (7.65,0.00) -- (7.80,0.00) -- (7.95,0.00) -- (8.10,0.00) -- (8.25,0.00) -- (8.40,0.00) -- (8.55,0.00) -- (8.70,0.00) -- (8.85,0.00) -- (9.00,0.00) -- (9.00,0) -- cycle;
\draw[cold, very thick] (0.00,0.00) -- (0.15,0.01) -- (0.30,0.01) -- (0.45,0.02) -- (0.60,0.03) -- (0.75,0.04) -- (0.90,0.07) -- (1.05,0.10) -- (1.20,0.14) -- (1.35,0.19) -- (1.50,0.26) -- (1.65,0.35) -- (1.80,0.46) -- (1.95,0.59) -- (2.10,0.73) -- (2.25,0.89) -- (2.40,1.07) -- (2.55,1.24) -- (2.70,1.42) -- (2.85,1.58) -- (3.00,1.72) -- (3.15,1.84) -- (3.30,1.92) -- (3.45,1.95) -- (3.60,1.94) -- (3.75,1.89) -- (3.90,1.80) -- (4.05,1.68) -- (4.20,1.53) -- (4.35,1.36) -- (4.50,1.19) -- (4.65,1.01) -- (4.80,0.84) -- (4.95,0.68) -- (5.10,0.54) -- (5.25,0.42) -- (5.40,0.32) -- (5.55,0.24) -- (5.70,0.17) -- (5.85,0.12) -- (6.00,0.09) -- (6.15,0.06) -- (6.30,0.04) -- (6.45,0.03) -- (6.60,0.02) -- (6.75,0.01) -- (6.90,0.01) -- (7.05,0.00) -- (7.20,0.00) -- (7.35,0.00) -- (7.50,0.00) -- (7.65,0.00) -- (7.80,0.00) -- (7.95,0.00) -- (8.10,0.00) -- (8.25,0.00) -- (8.40,0.00) -- (8.55,0.00) -- (8.70,0.00) -- (8.85,0.00) -- (9.00,0.00);
\draw[hot, very thick] (0.00,0.00) -- (0.15,0.00) -- (0.30,0.00) -- (0.45,0.00) -- (0.60,0.00) -- (0.75,0.00) -- (0.90,0.00) -- (1.05,0.00) -- (1.20,0.00) -- (1.35,0.00) -- (1.50,0.00) -- (1.65,0.00) -- (1.80,0.00) -- (1.95,0.00) -- (2.10,0.01) -- (2.25,0.01) -- (2.40,0.02) -- (2.55,0.03) -- (2.70,0.05) -- (2.85,0.07) -- (3.00,0.11) -- (3.15,0.15) -- (3.30,0.22) -- (3.45,0.30) -- (3.60,0.40) -- (3.75,0.53) -- (3.90,0.68) -- (4.05,0.85) -- (4.20,1.05) -- (4.35,1.26) -- (4.50,1.48) -- (4.65,1.70) -- (4.80,1.91) -- (4.95,2.09) -- (5.10,2.25) -- (5.25,2.36) -- (5.40,2.42) -- (5.55,2.43) -- (5.70,2.39) -- (5.85,2.29) -- (6.00,2.15) -- (6.15,1.97) -- (6.30,1.77) -- (6.45,1.55) -- (6.60,1.33) -- (6.75,1.11) -- (6.90,0.91) -- (7.05,0.73) -- (7.20,0.57) -- (7.35,0.44) -- (7.50,0.33) -- (7.65,0.24) -- (7.80,0.17) -- (7.95,0.12) -- (8.10,0.08) -- (8.25,0.06) -- (8.40,0.04) -- (8.55,0.02) -- (8.70,0.01) -- (8.85,0.01) -- (9.00,0.01);
\node[anchor=south east, inner sep=1pt] at (2.35,1.11) {$\pi_0\, p(x\mid 0)$};
\node[anchor=south west, inner sep=1pt] at (6.65,1.36) {$\pi_1\, p(x\mid 1)$};
\node[anchor=west] at (10.1,3.5) {$\pi_1 = 0.55, \ \pi_0 = 0.45$};
\draw[thick] (4.39,0) -- (4.39,2.78);
\node[anchor=east] at (4.31,-0.95) {\footnotesize predict $0$ $\leftarrow$};
\node[anchor=west] at (4.47,-0.95) {\footnotesize $\rightarrow$ predict $1$};
\node[anchor=west] at (10.1,2.8) {boundary $x^* = 0.89$};
\node[anchor=west] at (10.1,2.1) {Bayes error $= 0.157$};
\node[anchor=west] at (10.1,1.5) {\footnotesize $= 0.083$ (class $0$) ${}+ 0.074$ (class $1$)};
\node[anchor=west] at (-0.3,-1.75) {The prior $\pi_1$ grows. The red curve rises and the boundary moves toward the blue class.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 8.9s = "true", 9.15s = "false", 13.55s = "false", repeats}}}]
\fill[mid] (0.00,0) -- (0.00,0.00) -- (0.15,0.00) -- (0.30,0.00) -- (0.45,0.00) -- (0.60,0.00) -- (0.75,0.00) -- (0.90,0.00) -- (1.05,0.00) -- (1.20,0.00) -- (1.35,0.00) -- (1.50,0.00) -- (1.65,0.00) -- (1.80,0.00) -- (1.95,0.00) -- (2.10,0.01) -- (2.25,0.01) -- (2.40,0.02) -- (2.55,0.03) -- (2.70,0.05) -- (2.85,0.08) -- (3.00,0.12) -- (3.15,0.17) -- (3.30,0.24) -- (3.45,0.33) -- (3.60,0.44) -- (3.75,0.58) -- (3.90,0.75) -- (4.05,0.94) -- (4.20,1.15) -- (4.27,1.27) -- (4.35,1.19) -- (4.50,1.04) -- (4.65,0.88) -- (4.80,0.73) -- (4.95,0.60) -- (5.10,0.47) -- (5.25,0.37) -- (5.40,0.28) -- (5.55,0.21) -- (5.70,0.15) -- (5.85,0.11) -- (6.00,0.08) -- (6.15,0.05) -- (6.30,0.03) -- (6.45,0.02) -- (6.60,0.01) -- (6.75,0.01) -- (6.90,0.01) -- (7.05,0.00) -- (7.20,0.00) -- (7.35,0.00) -- (7.50,0.00) -- (7.65,0.00) -- (7.80,0.00) -- (7.95,0.00) -- (8.10,0.00) -- (8.25,0.00) -- (8.40,0.00) -- (8.55,0.00) -- (8.70,0.00) -- (8.85,0.00) -- (9.00,0.00) -- (9.00,0) -- cycle;
\draw[cold, very thick] (0.00,0.00) -- (0.15,0.01) -- (0.30,0.01) -- (0.45,0.02) -- (0.60,0.03) -- (0.75,0.04) -- (0.90,0.06) -- (1.05,0.08) -- (1.20,0.12) -- (1.35,0.17) -- (1.50,0.23) -- (1.65,0.31) -- (1.80,0.40) -- (1.95,0.51) -- (2.10,0.64) -- (2.25,0.78) -- (2.40,0.93) -- (2.55,1.09) -- (2.70,1.24) -- (2.85,1.38) -- (3.00,1.51) -- (3.15,1.61) -- (3.30,1.67) -- (3.45,1.71) -- (3.60,1.70) -- (3.75,1.66) -- (3.90,1.58) -- (4.05,1.47) -- (4.20,1.34) -- (4.35,1.19) -- (4.50,1.04) -- (4.65,0.88) -- (4.80,0.73) -- (4.95,0.60) -- (5.10,0.47) -- (5.25,0.37) -- (5.40,0.28) -- (5.55,0.21) -- (5.70,0.15) -- (5.85,0.11) -- (6.00,0.08) -- (6.15,0.05) -- (6.30,0.03) -- (6.45,0.02) -- (6.60,0.01) -- (6.75,0.01) -- (6.90,0.01) -- (7.05,0.00) -- (7.20,0.00) -- (7.35,0.00) -- (7.50,0.00) -- (7.65,0.00) -- (7.80,0.00) -- (7.95,0.00) -- (8.10,0.00) -- (8.25,0.00) -- (8.40,0.00) -- (8.55,0.00) -- (8.70,0.00) -- (8.85,0.00) -- (9.00,0.00);
\draw[hot, very thick] (0.00,0.00) -- (0.15,0.00) -- (0.30,0.00) -- (0.45,0.00) -- (0.60,0.00) -- (0.75,0.00) -- (0.90,0.00) -- (1.05,0.00) -- (1.20,0.00) -- (1.35,0.00) -- (1.50,0.00) -- (1.65,0.00) -- (1.80,0.00) -- (1.95,0.00) -- (2.10,0.01) -- (2.25,0.01) -- (2.40,0.02) -- (2.55,0.03) -- (2.70,0.05) -- (2.85,0.08) -- (3.00,0.12) -- (3.15,0.17) -- (3.30,0.24) -- (3.45,0.33) -- (3.60,0.44) -- (3.75,0.58) -- (3.90,0.75) -- (4.05,0.94) -- (4.20,1.15) -- (4.35,1.38) -- (4.50,1.63) -- (4.65,1.87) -- (4.80,2.10) -- (4.95,2.30) -- (5.10,2.47) -- (5.25,2.60) -- (5.40,2.67) -- (5.55,2.68) -- (5.70,2.63) -- (5.85,2.52) -- (6.00,2.37) -- (6.15,2.17) -- (6.30,1.95) -- (6.45,1.71) -- (6.60,1.46) -- (6.75,1.23) -- (6.90,1.01) -- (7.05,0.81) -- (7.20,0.63) -- (7.35,0.48) -- (7.50,0.36) -- (7.65,0.27) -- (7.80,0.19) -- (7.95,0.13) -- (8.10,0.09) -- (8.25,0.06) -- (8.40,0.04) -- (8.55,0.03) -- (8.70,0.02) -- (8.85,0.01) -- (9.00,0.01);
\node[anchor=south east, inner sep=1pt] at (2.35,0.98) {$\pi_0\, p(x\mid 0)$};
\node[anchor=south west, inner sep=1pt] at (6.65,1.48) {$\pi_1\, p(x\mid 1)$};
\node[anchor=west] at (10.1,3.5) {$\pi_1 = 0.61, \ \pi_0 = 0.39$};
\draw[thick] (4.27,0) -- (4.27,3.03);
\node[anchor=east] at (4.19,-0.95) {\footnotesize predict $0$ $\leftarrow$};
\node[anchor=west] at (4.35,-0.95) {\footnotesize $\rightarrow$ predict $1$};
\node[anchor=west] at (10.1,2.8) {boundary $x^* = 0.77$};
\node[anchor=west] at (10.1,2.1) {Bayes error $= 0.153$};
\node[anchor=west] at (10.1,1.5) {\footnotesize $= 0.085$ (class $0$) ${}+ 0.067$ (class $1$)};
\node[anchor=west] at (-0.3,-1.75) {The prior $\pi_1$ grows. The red curve rises and the boundary moves toward the blue class.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 9.15s = "true", 9.4s = "false", 13.55s = "false", repeats}}}]
\fill[mid] (0.00,0) -- (0.00,0.00) -- (0.15,0.00) -- (0.30,0.00) -- (0.45,0.00) -- (0.60,0.00) -- (0.75,0.00) -- (0.90,0.00) -- (1.05,0.00) -- (1.20,0.00) -- (1.35,0.00) -- (1.50,0.00) -- (1.65,0.00) -- (1.80,0.00) -- (1.95,0.01) -- (2.10,0.01) -- (2.25,0.02) -- (2.40,0.02) -- (2.55,0.04) -- (2.70,0.06) -- (2.85,0.09) -- (3.00,0.13) -- (3.15,0.19) -- (3.30,0.26) -- (3.45,0.36) -- (3.60,0.49) -- (3.75,0.64) -- (3.90,0.82) -- (4.05,1.04) -- (4.13,1.17) -- (4.20,1.12) -- (4.35,0.99) -- (4.50,0.87) -- (4.65,0.74) -- (4.80,0.61) -- (4.95,0.50) -- (5.10,0.40) -- (5.25,0.31) -- (5.40,0.23) -- (5.55,0.17) -- (5.70,0.13) -- (5.85,0.09) -- (6.00,0.06) -- (6.15,0.04) -- (6.30,0.03) -- (6.45,0.02) -- (6.60,0.01) -- (6.75,0.01) -- (6.90,0.00) -- (7.05,0.00) -- (7.20,0.00) -- (7.35,0.00) -- (7.50,0.00) -- (7.65,0.00) -- (7.80,0.00) -- (7.95,0.00) -- (8.10,0.00) -- (8.25,0.00) -- (8.40,0.00) -- (8.55,0.00) -- (8.70,0.00) -- (8.85,0.00) -- (9.00,0.00) -- (9.00,0) -- cycle;
\draw[cold, very thick] (0.00,0.00) -- (0.15,0.01) -- (0.30,0.01) -- (0.45,0.01) -- (0.60,0.02) -- (0.75,0.03) -- (0.90,0.05) -- (1.05,0.07) -- (1.20,0.10) -- (1.35,0.14) -- (1.50,0.19) -- (1.65,0.26) -- (1.80,0.34) -- (1.95,0.43) -- (2.10,0.54) -- (2.25,0.65) -- (2.40,0.78) -- (2.55,0.91) -- (2.70,1.04) -- (2.85,1.15) -- (3.00,1.26) -- (3.15,1.34) -- (3.30,1.40) -- (3.45,1.42) -- (3.60,1.42) -- (3.75,1.38) -- (3.90,1.32) -- (4.05,1.23) -- (4.20,1.12) -- (4.35,0.99) -- (4.50,0.87) -- (4.65,0.74) -- (4.80,0.61) -- (4.95,0.50) -- (5.10,0.40) -- (5.25,0.31) -- (5.40,0.23) -- (5.55,0.17) -- (5.70,0.13) -- (5.85,0.09) -- (6.00,0.06) -- (6.15,0.04) -- (6.30,0.03) -- (6.45,0.02) -- (6.60,0.01) -- (6.75,0.01) -- (6.90,0.00) -- (7.05,0.00) -- (7.20,0.00) -- (7.35,0.00) -- (7.50,0.00) -- (7.65,0.00) -- (7.80,0.00) -- (7.95,0.00) -- (8.10,0.00) -- (8.25,0.00) -- (8.40,0.00) -- (8.55,0.00) -- (8.70,0.00) -- (8.85,0.00) -- (9.00,0.00);
\draw[hot, very thick] (0.00,0.00) -- (0.15,0.00) -- (0.30,0.00) -- (0.45,0.00) -- (0.60,0.00) -- (0.75,0.00) -- (0.90,0.00) -- (1.05,0.00) -- (1.20,0.00) -- (1.35,0.00) -- (1.50,0.00) -- (1.65,0.00) -- (1.80,0.00) -- (1.95,0.01) -- (2.10,0.01) -- (2.25,0.02) -- (2.40,0.02) -- (2.55,0.04) -- (2.70,0.06) -- (2.85,0.09) -- (3.00,0.13) -- (3.15,0.19) -- (3.30,0.26) -- (3.45,0.36) -- (3.60,0.49) -- (3.75,0.64) -- (3.90,0.82) -- (4.05,1.04) -- (4.20,1.27) -- (4.35,1.53) -- (4.50,1.80) -- (4.65,2.06) -- (4.80,2.32) -- (4.95,2.55) -- (5.10,2.73) -- (5.25,2.87) -- (5.40,2.95) -- (5.55,2.96) -- (5.70,2.90) -- (5.85,2.79) -- (6.00,2.61) -- (6.15,2.40) -- (6.30,2.15) -- (6.45,1.89) -- (6.60,1.62) -- (6.75,1.36) -- (6.90,1.11) -- (7.05,0.89) -- (7.20,0.70) -- (7.35,0.54) -- (7.50,0.40) -- (7.65,0.29) -- (7.80,0.21) -- (7.95,0.15) -- (8.10,0.10) -- (8.25,0.07) -- (8.40,0.04) -- (8.55,0.03) -- (8.70,0.02) -- (8.85,0.01) -- (9.00,0.01);
\node[anchor=south east, inner sep=1pt] at (2.35,0.84) {$\pi_0\, p(x\mid 0)$};
\node[anchor=south west, inner sep=1pt] at (6.65,1.63) {$\pi_1\, p(x\mid 1)$};
\node[anchor=west] at (10.1,3.5) {$\pi_1 = 0.68, \ \pi_0 = 0.32$};
\draw[thick] (4.13,0) -- (4.13,3.31);
\node[anchor=east] at (4.05,-0.95) {\footnotesize predict $0$ $\leftarrow$};
\node[anchor=west] at (4.21,-0.95) {\footnotesize $\rightarrow$ predict $1$};
\node[anchor=west] at (10.1,2.8) {boundary $x^* = 0.63$};
\node[anchor=west] at (10.1,2.1) {Bayes error $= 0.144$};
\node[anchor=west] at (10.1,1.5) {\footnotesize $= 0.085$ (class $0$) ${}+ 0.058$ (class $1$)};
\node[anchor=west] at (-0.3,-1.75) {The prior $\pi_1$ grows. The red curve rises and the boundary moves toward the blue class.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 9.4s = "true", 9.65s = "false", 13.55s = "false", repeats}}}]
\fill[mid] (0.00,0) -- (0.00,0.00) -- (0.15,0.00) -- (0.30,0.00) -- (0.45,0.00) -- (0.60,0.00) -- (0.75,0.00) -- (0.90,0.00) -- (1.05,0.00) -- (1.20,0.00) -- (1.35,0.00) -- (1.50,0.00) -- (1.65,0.00) -- (1.80,0.00) -- (1.95,0.01) -- (2.10,0.01) -- (2.25,0.02) -- (2.40,0.03) -- (2.55,0.04) -- (2.70,0.06) -- (2.85,0.10) -- (3.00,0.14) -- (3.15,0.21) -- (3.30,0.29) -- (3.45,0.40) -- (3.60,0.53) -- (3.75,0.70) -- (3.90,0.90) -- (3.98,1.02) -- (4.05,0.98) -- (4.20,0.90) -- (4.35,0.80) -- (4.50,0.69) -- (4.65,0.59) -- (4.80,0.49) -- (4.95,0.40) -- (5.10,0.32) -- (5.25,0.25) -- (5.40,0.19) -- (5.55,0.14) -- (5.70,0.10) -- (5.85,0.07) -- (6.00,0.05) -- (6.15,0.03) -- (6.30,0.02) -- (6.45,0.01) -- (6.60,0.01) -- (6.75,0.01) -- (6.90,0.00) -- (7.05,0.00) -- (7.20,0.00) -- (7.35,0.00) -- (7.50,0.00) -- (7.65,0.00) -- (7.80,0.00) -- (7.95,0.00) -- (8.10,0.00) -- (8.25,0.00) -- (8.40,0.00) -- (8.55,0.00) -- (8.70,0.00) -- (8.85,0.00) -- (9.00,0.00) -- (9.00,0) -- cycle;
\draw[cold, very thick] (0.00,0.00) -- (0.15,0.00) -- (0.30,0.01) -- (0.45,0.01) -- (0.60,0.02) -- (0.75,0.03) -- (0.90,0.04) -- (1.05,0.06) -- (1.20,0.08) -- (1.35,0.11) -- (1.50,0.15) -- (1.65,0.21) -- (1.80,0.27) -- (1.95,0.34) -- (2.10,0.43) -- (2.25,0.52) -- (2.40,0.62) -- (2.55,0.73) -- (2.70,0.83) -- (2.85,0.93) -- (3.00,1.01) -- (3.15,1.08) -- (3.30,1.12) -- (3.45,1.14) -- (3.60,1.14) -- (3.75,1.11) -- (3.90,1.06) -- (4.05,0.98) -- (4.20,0.90) -- (4.35,0.80) -- (4.50,0.69) -- (4.65,0.59) -- (4.80,0.49) -- (4.95,0.40) -- (5.10,0.32) -- (5.25,0.25) -- (5.40,0.19) -- (5.55,0.14) -- (5.70,0.10) -- (5.85,0.07) -- (6.00,0.05) -- (6.15,0.03) -- (6.30,0.02) -- (6.45,0.01) -- (6.60,0.01) -- (6.75,0.01) -- (6.90,0.00) -- (7.05,0.00) -- (7.20,0.00) -- (7.35,0.00) -- (7.50,0.00) -- (7.65,0.00) -- (7.80,0.00) -- (7.95,0.00) -- (8.10,0.00) -- (8.25,0.00) -- (8.40,0.00) -- (8.55,0.00) -- (8.70,0.00) -- (8.85,0.00) -- (9.00,0.00);
\draw[hot, very thick] (0.00,0.00) -- (0.15,0.00) -- (0.30,0.00) -- (0.45,0.00) -- (0.60,0.00) -- (0.75,0.00) -- (0.90,0.00) -- (1.05,0.00) -- (1.20,0.00) -- (1.35,0.00) -- (1.50,0.00) -- (1.65,0.00) -- (1.80,0.00) -- (1.95,0.01) -- (2.10,0.01) -- (2.25,0.02) -- (2.40,0.03) -- (2.55,0.04) -- (2.70,0.06) -- (2.85,0.10) -- (3.00,0.14) -- (3.15,0.21) -- (3.30,0.29) -- (3.45,0.40) -- (3.60,0.53) -- (3.75,0.70) -- (3.90,0.90) -- (4.05,1.13) -- (4.20,1.39) -- (4.35,1.67) -- (4.50,1.97) -- (4.65,2.26) -- (4.80,2.54) -- (4.95,2.79) -- (5.10,2.99) -- (5.25,3.14) -- (5.40,3.23) -- (5.55,3.24) -- (5.70,3.18) -- (5.85,3.05) -- (6.00,2.86) -- (6.15,2.63) -- (6.30,2.36) -- (6.45,2.07) -- (6.60,1.77) -- (6.75,1.49) -- (6.90,1.22) -- (7.05,0.98) -- (7.20,0.76) -- (7.35,0.59) -- (7.50,0.44) -- (7.65,0.32) -- (7.80,0.23) -- (7.95,0.16) -- (8.10,0.11) -- (8.25,0.07) -- (8.40,0.05) -- (8.55,0.03) -- (8.70,0.02) -- (8.85,0.01) -- (9.00,0.01);
\node[anchor=south east, inner sep=1pt] at (2.35,0.69) {$\pi_0\, p(x\mid 0)$};
\node[anchor=south west, inner sep=1pt] at (6.65,1.77) {$\pi_1\, p(x\mid 1)$};
\node[anchor=west] at (10.1,3.5) {$\pi_1 = 0.74, \ \pi_0 = 0.26$};
\draw[thick] (3.98,0) -- (3.98,3.59);
\node[anchor=east] at (3.90,-0.95) {\footnotesize predict $0$ $\leftarrow$};
\node[anchor=west] at (4.06,-0.95) {\footnotesize $\rightarrow$ predict $1$};
\node[anchor=west] at (10.1,2.8) {boundary $x^* = 0.48$};
\node[anchor=west] at (10.1,2.1) {Bayes error $= 0.130$};
\node[anchor=west] at (10.1,1.5) {\footnotesize $= 0.082$ (class $0$) ${}+ 0.047$ (class $1$)};
\node[anchor=west] at (-0.3,-1.75) {The prior $\pi_1$ grows. The red curve rises and the boundary moves toward the blue class.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 9.65s = "true", 9.9s = "false", 13.55s = "false", repeats}}}]
\fill[mid] (0.00,0) -- (0.00,0.00) -- (0.15,0.00) -- (0.30,0.00) -- (0.45,0.00) -- (0.60,0.00) -- (0.75,0.00) -- (0.90,0.00) -- (1.05,0.00) -- (1.20,0.00) -- (1.35,0.00) -- (1.50,0.00) -- (1.65,0.00) -- (1.80,0.00) -- (1.95,0.01) -- (2.10,0.01) -- (2.25,0.02) -- (2.40,0.03) -- (2.55,0.04) -- (2.70,0.07) -- (2.85,0.10) -- (3.00,0.15) -- (3.15,0.22) -- (3.30,0.31) -- (3.45,0.43) -- (3.60,0.57) -- (3.75,0.75) -- (3.82,0.85) -- (3.90,0.83) -- (4.05,0.77) -- (4.20,0.70) -- (4.35,0.63) -- (4.50,0.54) -- (4.65,0.46) -- (4.80,0.39) -- (4.95,0.31) -- (5.10,0.25) -- (5.25,0.19) -- (5.40,0.15) -- (5.55,0.11) -- (5.70,0.08) -- (5.85,0.06) -- (6.00,0.04) -- (6.15,0.03) -- (6.30,0.02) -- (6.45,0.01) -- (6.60,0.01) -- (6.75,0.00) -- (6.90,0.00) -- (7.05,0.00) -- (7.20,0.00) -- (7.35,0.00) -- (7.50,0.00) -- (7.65,0.00) -- (7.80,0.00) -- (7.95,0.00) -- (8.10,0.00) -- (8.25,0.00) -- (8.40,0.00) -- (8.55,0.00) -- (8.70,0.00) -- (8.85,0.00) -- (9.00,0.00) -- (9.00,0) -- cycle;
\draw[cold, very thick] (0.00,0.00) -- (0.15,0.00) -- (0.30,0.01) -- (0.45,0.01) -- (0.60,0.01) -- (0.75,0.02) -- (0.90,0.03) -- (1.05,0.04) -- (1.20,0.06) -- (1.35,0.09) -- (1.50,0.12) -- (1.65,0.16) -- (1.80,0.21) -- (1.95,0.27) -- (2.10,0.34) -- (2.25,0.41) -- (2.40,0.49) -- (2.55,0.57) -- (2.70,0.65) -- (2.85,0.73) -- (3.00,0.79) -- (3.15,0.84) -- (3.30,0.88) -- (3.45,0.90) -- (3.60,0.89) -- (3.75,0.87) -- (3.90,0.83) -- (4.05,0.77) -- (4.20,0.70) -- (4.35,0.63) -- (4.50,0.54) -- (4.65,0.46) -- (4.80,0.39) -- (4.95,0.31) -- (5.10,0.25) -- (5.25,0.19) -- (5.40,0.15) -- (5.55,0.11) -- (5.70,0.08) -- (5.85,0.06) -- (6.00,0.04) -- (6.15,0.03) -- (6.30,0.02) -- (6.45,0.01) -- (6.60,0.01) -- (6.75,0.00) -- (6.90,0.00) -- (7.05,0.00) -- (7.20,0.00) -- (7.35,0.00) -- (7.50,0.00) -- (7.65,0.00) -- (7.80,0.00) -- (7.95,0.00) -- (8.10,0.00) -- (8.25,0.00) -- (8.40,0.00) -- (8.55,0.00) -- (8.70,0.00) -- (8.85,0.00) -- (9.00,0.00);
\draw[hot, very thick] (0.00,0.00) -- (0.15,0.00) -- (0.30,0.00) -- (0.45,0.00) -- (0.60,0.00) -- (0.75,0.00) -- (0.90,0.00) -- (1.05,0.00) -- (1.20,0.00) -- (1.35,0.00) -- (1.50,0.00) -- (1.65,0.00) -- (1.80,0.00) -- (1.95,0.01) -- (2.10,0.01) -- (2.25,0.02) -- (2.40,0.03) -- (2.55,0.04) -- (2.70,0.07) -- (2.85,0.10) -- (3.00,0.15) -- (3.15,0.22) -- (3.30,0.31) -- (3.45,0.43) -- (3.60,0.57) -- (3.75,0.75) -- (3.90,0.97) -- (4.05,1.22) -- (4.20,1.50) -- (4.35,1.80) -- (4.50,2.12) -- (4.65,2.43) -- (4.80,2.73) -- (4.95,3.00) -- (5.10,3.22) -- (5.25,3.38) -- (5.40,3.47) -- (5.55,3.49) -- (5.70,3.42) -- (5.85,3.28) -- (6.00,3.08) -- (6.15,2.83) -- (6.30,2.53) -- (6.45,2.22) -- (6.60,1.91) -- (6.75,1.60) -- (6.90,1.31) -- (7.05,1.05) -- (7.20,0.82) -- (7.35,0.63) -- (7.50,0.47) -- (7.65,0.35) -- (7.80,0.25) -- (7.95,0.17) -- (8.10,0.12) -- (8.25,0.08) -- (8.40,0.05) -- (8.55,0.03) -- (8.70,0.02) -- (8.85,0.01) -- (9.00,0.01);
\node[anchor=south east, inner sep=1pt] at (2.35,0.56) {$\pi_0\, p(x\mid 0)$};
\node[anchor=south west, inner sep=1pt] at (6.65,1.90) {$\pi_1\, p(x\mid 1)$};
\node[anchor=west] at (10.1,3.5) {$\pi_1 = 0.80, \ \pi_0 = 0.20$};
\draw[thick] (3.82,0) -- (3.82,3.84);
\node[anchor=east] at (3.74,-0.95) {\footnotesize predict $0$ $\leftarrow$};
\node[anchor=west] at (3.90,-0.95) {\footnotesize $\rightarrow$ predict $1$};
\node[anchor=west] at (10.1,2.8) {boundary $x^* = 0.32$};
\node[anchor=west] at (10.1,2.1) {Bayes error $= 0.114$};
\node[anchor=west] at (10.1,1.5) {\footnotesize $= 0.077$ (class $0$) ${}+ 0.037$ (class $1$)};
\node[anchor=west] at (-0.3,-1.75) {The prior $\pi_1$ grows. The red curve rises and the boundary moves toward the blue class.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 9.9s = "true", 10.15s = "false", 13.55s = "false", repeats}}}]
\fill[mid] (0.00,0) -- (0.00,0.00) -- (0.15,0.00) -- (0.30,0.00) -- (0.45,0.00) -- (0.60,0.00) -- (0.75,0.00) -- (0.90,0.00) -- (1.05,0.00) -- (1.20,0.00) -- (1.35,0.00) -- (1.50,0.00) -- (1.65,0.00) -- (1.80,0.00) -- (1.95,0.01) -- (2.10,0.01) -- (2.25,0.02) -- (2.40,0.03) -- (2.55,0.05) -- (2.70,0.07) -- (2.85,0.11) -- (3.00,0.16) -- (3.15,0.23) -- (3.30,0.33) -- (3.45,0.45) -- (3.60,0.60) -- (3.69,0.71) -- (3.75,0.70) -- (3.90,0.67) -- (4.05,0.62) -- (4.20,0.57) -- (4.35,0.50) -- (4.50,0.44) -- (4.65,0.37) -- (4.80,0.31) -- (4.95,0.25) -- (5.10,0.20) -- (5.25,0.16) -- (5.40,0.12) -- (5.55,0.09) -- (5.70,0.06) -- (5.85,0.05) -- (6.00,0.03) -- (6.15,0.02) -- (6.30,0.01) -- (6.45,0.01) -- (6.60,0.01) -- (6.75,0.00) -- (6.90,0.00) -- (7.05,0.00) -- (7.20,0.00) -- (7.35,0.00) -- (7.50,0.00) -- (7.65,0.00) -- (7.80,0.00) -- (7.95,0.00) -- (8.10,0.00) -- (8.25,0.00) -- (8.40,0.00) -- (8.55,0.00) -- (8.70,0.00) -- (8.85,0.00) -- (9.00,0.00) -- (9.00,0) -- cycle;
\draw[cold, very thick] (0.00,0.00) -- (0.15,0.00) -- (0.30,0.00) -- (0.45,0.01) -- (0.60,0.01) -- (0.75,0.02) -- (0.90,0.02) -- (1.05,0.04) -- (1.20,0.05) -- (1.35,0.07) -- (1.50,0.10) -- (1.65,0.13) -- (1.80,0.17) -- (1.95,0.22) -- (2.10,0.27) -- (2.25,0.33) -- (2.40,0.40) -- (2.55,0.46) -- (2.70,0.53) -- (2.85,0.59) -- (3.00,0.64) -- (3.15,0.68) -- (3.30,0.71) -- (3.45,0.72) -- (3.60,0.72) -- (3.75,0.70) -- (3.90,0.67) -- (4.05,0.62) -- (4.20,0.57) -- (4.35,0.50) -- (4.50,0.44) -- (4.65,0.37) -- (4.80,0.31) -- (4.95,0.25) -- (5.10,0.20) -- (5.25,0.16) -- (5.40,0.12) -- (5.55,0.09) -- (5.70,0.06) -- (5.85,0.05) -- (6.00,0.03) -- (6.15,0.02) -- (6.30,0.01) -- (6.45,0.01) -- (6.60,0.01) -- (6.75,0.00) -- (6.90,0.00) -- (7.05,0.00) -- (7.20,0.00) -- (7.35,0.00) -- (7.50,0.00) -- (7.65,0.00) -- (7.80,0.00) -- (7.95,0.00) -- (8.10,0.00) -- (8.25,0.00) -- (8.40,0.00) -- (8.55,0.00) -- (8.70,0.00) -- (8.85,0.00) -- (9.00,0.00);
\draw[hot, very thick] (0.00,0.00) -- (0.15,0.00) -- (0.30,0.00) -- (0.45,0.00) -- (0.60,0.00) -- (0.75,0.00) -- (0.90,0.00) -- (1.05,0.00) -- (1.20,0.00) -- (1.35,0.00) -- (1.50,0.00) -- (1.65,0.00) -- (1.80,0.00) -- (1.95,0.01) -- (2.10,0.01) -- (2.25,0.02) -- (2.40,0.03) -- (2.55,0.05) -- (2.70,0.07) -- (2.85,0.11) -- (3.00,0.16) -- (3.15,0.23) -- (3.30,0.33) -- (3.45,0.45) -- (3.60,0.60) -- (3.75,0.79) -- (3.90,1.02) -- (4.05,1.28) -- (4.20,1.57) -- (4.35,1.89) -- (4.50,2.22) -- (4.65,2.55) -- (4.80,2.87) -- (4.95,3.15) -- (5.10,3.38) -- (5.25,3.55) -- (5.40,3.65) -- (5.55,3.66) -- (5.70,3.59) -- (5.85,3.45) -- (6.00,3.23) -- (6.15,2.97) -- (6.30,2.66) -- (6.45,2.33) -- (6.60,2.00) -- (6.75,1.68) -- (6.90,1.38) -- (7.05,1.10) -- (7.20,0.86) -- (7.35,0.66) -- (7.50,0.50) -- (7.65,0.36) -- (7.80,0.26) -- (7.95,0.18) -- (8.10,0.12) -- (8.25,0.08) -- (8.40,0.05) -- (8.55,0.03) -- (8.70,0.02) -- (8.85,0.01) -- (9.00,0.01);
\node[anchor=south east, inner sep=1pt] at (2.35,0.47) {$\pi_0\, p(x\mid 0)$};
\node[anchor=south west, inner sep=1pt] at (6.65,1.99) {$\pi_1\, p(x\mid 1)$};
\node[anchor=west] at (10.1,3.5) {$\pi_1 = 0.83, \ \pi_0 = 0.17$};
\draw[thick] (3.69,0) -- (3.69,4.01);
\node[anchor=east] at (3.61,-0.95) {\footnotesize predict $0$ $\leftarrow$};
\node[anchor=west] at (3.77,-0.95) {\footnotesize $\rightarrow$ predict $1$};
\node[anchor=west] at (10.1,2.8) {boundary $x^* = 0.19$};
\node[anchor=west] at (10.1,2.1) {Bayes error $= 0.099$};
\node[anchor=west] at (10.1,1.5) {\footnotesize $= 0.070$ (class $0$) ${}+ 0.029$ (class $1$)};
\node[anchor=west] at (-0.3,-1.75) {The prior $\pi_1$ grows. The red curve rises and the boundary moves toward the blue class.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 10.15s = "true", 13.55s = "true", repeats}}}]
\fill[mid] (0.00,0) -- (0.00,0.00) -- (0.15,0.00) -- (0.30,0.00) -- (0.45,0.00) -- (0.60,0.00) -- (0.75,0.00) -- (0.90,0.00) -- (1.05,0.00) -- (1.20,0.00) -- (1.35,0.00) -- (1.50,0.00) -- (1.65,0.00) -- (1.80,0.00) -- (1.95,0.01) -- (2.10,0.01) -- (2.25,0.02) -- (2.40,0.03) -- (2.55,0.05) -- (2.70,0.07) -- (2.85,0.11) -- (3.00,0.16) -- (3.15,0.24) -- (3.30,0.33) -- (3.45,0.46) -- (3.60,0.61) -- (3.63,0.65) -- (3.75,0.64) -- (3.90,0.61) -- (4.05,0.57) -- (4.20,0.52) -- (4.35,0.46) -- (4.50,0.40) -- (4.65,0.34) -- (4.80,0.28) -- (4.95,0.23) -- (5.10,0.18) -- (5.25,0.14) -- (5.40,0.11) -- (5.55,0.08) -- (5.70,0.06) -- (5.85,0.04) -- (6.00,0.03) -- (6.15,0.02) -- (6.30,0.01) -- (6.45,0.01) -- (6.60,0.01) -- (6.75,0.00) -- (6.90,0.00) -- (7.05,0.00) -- (7.20,0.00) -- (7.35,0.00) -- (7.50,0.00) -- (7.65,0.00) -- (7.80,0.00) -- (7.95,0.00) -- (8.10,0.00) -- (8.25,0.00) -- (8.40,0.00) -- (8.55,0.00) -- (8.70,0.00) -- (8.85,0.00) -- (9.00,0.00) -- (9.00,0) -- cycle;
\draw[cold, very thick] (0.00,0.00) -- (0.15,0.00) -- (0.30,0.00) -- (0.45,0.01) -- (0.60,0.01) -- (0.75,0.02) -- (0.90,0.02) -- (1.05,0.03) -- (1.20,0.05) -- (1.35,0.07) -- (1.50,0.09) -- (1.65,0.12) -- (1.80,0.16) -- (1.95,0.20) -- (2.10,0.25) -- (2.25,0.30) -- (2.40,0.36) -- (2.55,0.42) -- (2.70,0.48) -- (2.85,0.53) -- (3.00,0.58) -- (3.15,0.62) -- (3.30,0.65) -- (3.45,0.66) -- (3.60,0.65) -- (3.75,0.64) -- (3.90,0.61) -- (4.05,0.57) -- (4.20,0.52) -- (4.35,0.46) -- (4.50,0.40) -- (4.65,0.34) -- (4.80,0.28) -- (4.95,0.23) -- (5.10,0.18) -- (5.25,0.14) -- (5.40,0.11) -- (5.55,0.08) -- (5.70,0.06) -- (5.85,0.04) -- (6.00,0.03) -- (6.15,0.02) -- (6.30,0.01) -- (6.45,0.01) -- (6.60,0.01) -- (6.75,0.00) -- (6.90,0.00) -- (7.05,0.00) -- (7.20,0.00) -- (7.35,0.00) -- (7.50,0.00) -- (7.65,0.00) -- (7.80,0.00) -- (7.95,0.00) -- (8.10,0.00) -- (8.25,0.00) -- (8.40,0.00) -- (8.55,0.00) -- (8.70,0.00) -- (8.85,0.00) -- (9.00,0.00);
\draw[hot, very thick] (0.00,0.00) -- (0.15,0.00) -- (0.30,0.00) -- (0.45,0.00) -- (0.60,0.00) -- (0.75,0.00) -- (0.90,0.00) -- (1.05,0.00) -- (1.20,0.00) -- (1.35,0.00) -- (1.50,0.00) -- (1.65,0.00) -- (1.80,0.00) -- (1.95,0.01) -- (2.10,0.01) -- (2.25,0.02) -- (2.40,0.03) -- (2.55,0.05) -- (2.70,0.07) -- (2.85,0.11) -- (3.00,0.16) -- (3.15,0.24) -- (3.30,0.33) -- (3.45,0.46) -- (3.60,0.61) -- (3.75,0.81) -- (3.90,1.04) -- (4.05,1.30) -- (4.20,1.60) -- (4.35,1.93) -- (4.50,2.26) -- (4.65,2.60) -- (4.80,2.92) -- (4.95,3.21) -- (5.10,3.44) -- (5.25,3.62) -- (5.40,3.71) -- (5.55,3.73) -- (5.70,3.66) -- (5.85,3.51) -- (6.00,3.29) -- (6.15,3.02) -- (6.30,2.71) -- (6.45,2.38) -- (6.60,2.04) -- (6.75,1.71) -- (6.90,1.40) -- (7.05,1.12) -- (7.20,0.88) -- (7.35,0.67) -- (7.50,0.50) -- (7.65,0.37) -- (7.80,0.26) -- (7.95,0.19) -- (8.10,0.13) -- (8.25,0.09) -- (8.40,0.06) -- (8.55,0.04) -- (8.70,0.02) -- (8.85,0.01) -- (9.00,0.01);
\node[anchor=south east, inner sep=1pt] at (2.35,0.44) {$\pi_0\, p(x\mid 0)$};
\node[anchor=south west, inner sep=1pt] at (6.65,2.03) {$\pi_1\, p(x\mid 1)$};
\node[anchor=west] at (10.1,3.5) {$\pi_1 = 0.85, \ \pi_0 = 0.15$};
\draw[thick] (3.63,0) -- (3.63,4.08);
\node[anchor=east] at (3.55,-0.95) {\footnotesize predict $0$ $\leftarrow$};
\node[anchor=west] at (3.71,-0.95) {\footnotesize $\rightarrow$ predict $1$};
\node[anchor=west] at (10.1,2.8) {boundary $x^* = 0.13$};
\node[anchor=west] at (10.1,2.1) {Bayes error $= 0.093$};
\node[anchor=west] at (10.1,1.5) {\footnotesize $= 0.067$ (class $0$) ${}+ 0.026$ (class $1$)};
\node[anchor=west] at (-0.3,-1.75) {With $\pi_1 = 0.85$ the boundary moves to $x^* = 0.13$ and the Bayes error falls to $0.093$.};
\end{scope}
\end{tikzpicture}
\end{document}Properties
(Zero Bayes Error) The Bayes error is zero only when the label is a deterministic function of the input.
For two classes, write . The Bayes error becomes , which vanishes only if is or for almost every input. Label noise and missing features keep away from and . An informative new feature can lower , because the posterior then conditions on more information. When the training error falls far below any plausible Bayes error, the model is overfitting. It has then fit noise that no rule can predict on new data.
(Separable Is Not Error-Free) A linearly separable training set says little when the dimension is large compared with the sample size.
Any points in general position in are linearly separable under all labelings. Cover (1965) counted the separable labelings for larger . At points, exactly half of all labelings are separable. A separable sample in many dimensions can therefore arise by chance, even when the classes overlap heavily. On separable data, unregularized logistic regression has no finite solution, and its weights grow without bound.
(Shifting Priors) When class frequencies change between training and deployment, the posterior odds change by the ratio of the priors.
Bayes’ rule in odds form splits the posterior odds into a likelihood ratio and the prior odds:
A generative model can adapt to new priors by swapping them in, with no retraining (Bishop, PRML, sec. 1.5.4). A discriminative model needs its log-odds shifted by . This correction assumes the class densities stay the same. A model trained on balanced data and deployed where 1% of cases are positive needs a shift of .
(Reject Option) A classifier can refuse to decide when its largest posterior is too small.
With a threshold , the rule outputs a class only when and defers otherwise (Bishop, PRML, sec. 1.5.3). Raising toward rejects more inputs, and any rejects none. A screening model in a hospital can pass its uncertain cases to a doctor. The error rate on the accepted inputs falls as the reject rate rises. The rule needs calibrated probabilities, which log loss measures.
(Generative Versus Discriminative) Generative classifiers often win with little data, and discriminative classifiers often win with a lot.
A generative model must describe the whole input distribution, which is hard when is large. In exchange, its extra assumptions give it lower variance. Ng and Jordan (2002) compared naive Bayes with logistic regression on the same features. Naive Bayes approached its limiting error with a number of samples logarithmic in . Logistic regression needed a number linear in . Logistic regression reached a lower limiting error when the naive Bayes independence assumption was wrong.
Derivation
We want to show that no classifier has a lower 0-1 risk than . Conditioning on the input, the law of total expectation gives
The choice of at one input does not affect the bracket at any other input. So the risk is smallest when the bracket is smallest at each separately. The bracket is smallest for the class with the largest posterior, which is . The bracket then equals , and its expectation is .
The same argument handles costs. Fix an input and write . Predicting costs when , so its expected cost is . Predicting has expected cost . Predicting is cheaper when , which rearranges to . In terms of densities, the rule predicts when the likelihood ratio exceeds .
Examples
(Easy) A One-Word Spam Filter
A spam filter sees one feature: whether an email contains the word “free”. Of all emails, 30% are spam. The word appears in 60% of spam emails and in 5% of legitimate ones.
What does the Bayes classifier predict for each kind of email, and what is its error rate? for spam and for legitimate mail. The posterior is , so the filter predicts spam. For emails without the word, the joint probabilities are and . The posterior of spam is , so the filter predicts legitimate. The errors are the legitimate emails with "free" and the spam emails without it, so . No filter that sees only this feature can do better than 15.5%.
For emails with “free”, the joint probabilities are
(Medium) Vibration Sensors and a Rare Fault
A factory measures the vibration of each pump. Healthy pumps give and faulty pumps give .
Find the Bayes threshold and error when half the pumps are faulty. Then repeat with 10% faulty, and check the old threshold under the new rate. . Each class falls on the wrong side with probability , where is the standard normal CDF. The Bayes error is . With , the posterior odds of a fault are . They exceed when . The Bayes error drops to . Keeping the old threshold still gives error . That is worse than calling every pump healthy, which errs on the 10% that are faulty.
With equal priors the two densities cross at the midpoint, so the Bayes classifier predicts “faulty” for
(Hard) When a Missed Fault Costs Ten False Alarms
Continue with 10% faulty pumps. A missed fault costs $5000 in damage, and a false alarm costs $500 for an inspection.
Find the cost-minimizing threshold on and compare its expected cost and error rate with the error-minimizing rule. The posterior threshold is , so the odds threshold is . Setting gives . At this threshold the false-alarm rate per pump is . The miss rate is . The expected cost is 500 \cdot 0.1546 + 5000 \cdot 0.01462 = \150.402.099$277.70$500$45016.9%7.0%$, but most of them are cheap false alarms.
See Also
- 4.2. Linear Discriminants, where Gaussian class densities turn the Bayes rule into LDA and QDA.
- 6.5. Naive Bayes, a generative classifier that assumes features are independent given the class.
- 4.3. Logistic Regression, the standard discriminative model of the posterior.
- 4.5. k-Nearest Neighbors, whose 1-NN error is at most twice the Bayes error in the limit of infinite data.
- 2.2.1. Confusion Matrix, for the error counts behind false alarms and misses.