07 - Exercise Lab

Pattern Recognition and Machine Learning, Lab 7

Michal Neoral

neoramic@fel.cvut.cz

6 November 2026

Today

Plan for today

Three problems

  • maximum likelihood
  • Parzen windows
  • Neyman-Pearson
  • Bayes with a reject option

All from previous tests.

Next week

  • Test 2 on 13 November
  • at the start of the lab
  • bring a calculator

test

Try each problem yourself first. Then click to reveal the results, Exercise 3 is solved step by step.

Exercise 1: maximum likelihood

Exercise 1: light bulbs

Test 2019, 8 points: maximum likelihood estimate of the bulb lifetime parameter theta from six lifetimes, from a test that ended at time T, and from the counts of good and failed bulbs

Exercise 1: results

  1. \(\quad \hML{\theta} = \dfrac{0 + 1 + 2.3 + 2.7 + 6 + 12}{6} = 4.0\)
  1. \(\quad \hML{\theta} = \dfrac{0 + 1 + 2.3 + 2.7 + 2 \cdot 4}{4} = 3.5\)
  1. \(\quad \hML{\theta} = \dfrac{T}{\ln \frac{F + G}{G}}, \qquad\) for \(T = 4\), \(F = 4\), \(G = 2\): \(\quad \hML{\theta} = \dfrac{4}{\ln 3} \approx 3.64\)

Exercise 2: Parzen and Neyman-Pearson

Exercise 2: Parzen and Neyman-Pearson

Test 2021, 6 points: Parzen window estimates of two class densities with a box kernel of width 2, then the Neyman-Pearson strategy for overlooked danger below 40 percent

Exercise 2: results

  1. \(\quad \cph(0.5 \mid \cone) = \dfrac{3}{5 \cdot 2} = 0.3, \qquad \cph(0.5 \mid \ctwo) = \dfrac{2}{4 \cdot 2} = 0.25\)
  1. \(\quad \cq(x) = \begin{cases} \cone & 0 \le x < 2 \\ \ctwo & \text{otherwise} \end{cases} \qquad \eone = 0.4, \quad \etwo = 0.375\)

Even better: add a piece with \(\cr = 0.8\) and mass \(\cph(x \mid \ctwo) = 0.025\) to fill \(\etwo\) up to \(0.4\). There are infinitely many such pieces, e.g. \([2, 2.2)\) or \([-0.1, 0)\), all give \(\eone = 0.4 - 0.8 \cdot 0.025 = 0.38\): \[ \cq(x) = \begin{cases} \cone & 0 \le x < 2.2 \\ \ctwo & \text{otherwise} \end{cases} \qquad \eone = 0.38, \quad \etwo = 0.4 \]

Exercise 3: Bayes with a reject option

Exercise 3: two normal classes

Test 2019, 6 points, in Czech: Bayesian classification of two normal classes with equal priors, means (3, 6) and (3, -2), covariances 2 times identity; minimal error classifier, reject option for 0.1, and asymmetric loss W(1,2) = 2, W(2,1) = 1

Derivation: (a) minimal error

Equal priors, decide by the log ratio of the likelihoods: \[ a(\cx) = \ln \frac{\cp(\cx \mid \cone)}{\cp(\cx \mid \ctwo)} = \frac{\|\cx - \mu_{\ctwo}\|^2 - \|\cx - \mu_{\cone}\|^2}{4} \]

The terms with \(x_1\) cancel: \[ a(\cx) = \frac{(x_2 + 2)^2 - (x_2 - 6)^2}{4} = 4 x_2 - 8 \]

\[ \cq(\cx) = \begin{cases} \cone & x_2 > 2 \\ \ctwo & x_2 \le 2 \end{cases} \]

A line halfway between the means.

Two circular normal classes above each other and the horizontal decision line x2 = 2

Derivation: (b) reject option

Bayes with "not known" (Lab 3): decide the most probable class if \[ 1 - \max_{\ck} \cp(\ck \mid \cx) < 0.1 \quad\Leftrightarrow\quad \max_{\ck} \cp(\ck \mid \cx) > 0.9 \]

From (a): \(\cp(\cone \mid \cx) = \sigma(a(\cx))\) and \(\sigma(a) > 0.9 \Leftrightarrow a > \ln 9\) \[ \text{not known} \;\Leftrightarrow\; |4 x_2 - 8| < \ln 9 \;\Leftrightarrow\; |x_2 - 2| < 0.549 \]

\[ \cq(\cx) = \begin{cases} \cone & x_2 \ge 2.549 \\ \text{not known} & 1.451 < x_2 < 2.549 \\ \ctwo & x_2 \le 1.451 \end{cases} \]

A grey band around the line x2 = 2 where the strategy says not known

Derivation: (c) asymmetric loss

Risk of each decision: \[ \begin{aligned} R(\cone \mid \cx) &= \cW(\ctwo, \cone)\, \cp(\ctwo \mid \cx) = \cp(\ctwo \mid \cx) \\ R(\ctwo \mid \cx) &= \cW(\cone, \ctwo)\, \cp(\cone \mid \cx) = 2\, \cp(\cone \mid \cx) \end{aligned} \]

Decide \(\cone\) if \[ \cp(\ctwo \mid \cx) < 2\, \cp(\cone \mid \cx) \;\Leftrightarrow\; a(\cx) > -\ln 2 \]

so \(\; x_2 > 2 - \frac{\ln 2}{4} \approx 1.827\)

\[ \cq(\cx) = \begin{cases} \cone & x_2 > 1.827 \\ \ctwo & x_2 \le 1.827 \end{cases} \]

An error on class \(\cone\) is expensive: the boundary moves towards \(\mu_{\ctwo}\).

The decision line moved slightly down to x2 = 1.827

Take-away for the lab

  • Censored data: a bulb that still works contributes \(P(t > T)\), not a density
  • Only counts: a binomial likelihood, as for the socks
  • Parzen with a box kernel: a step function, count the boxes
  • Neyman-Pearson: sort by \(\cr(x)\), add regions until the limit
  • Equal covariances: linear log odds, reject and loss shift the threshold