first-course-ml

Chapter 5: Classification, a quick recap

Short revision notes. Exercises are not covered.

The problem

Given \(N\) training objects \(\mathbf{x}_n\) (vectors of dimension \(D\)) with class labels \(t_n\) (e.g. \(\{0,1\}\), \(\{-1,1\}\) or \(\{1,\dots,C\}\)), predict the class of a new object. It is the same setup as regression in Chapters 1 to 3, except the response is a class label instead of a real number. The binary response model of Chapter 4 is already a classifier (logistic regression). The chapter presents four algorithms, two probabilistic and two not.

Probabilistic classifiers

They output \(P(t_{\text{new}}=c\mid\mathbf{x}_{\text{new}},\mathbf{X},\mathbf{t})\) for every class. The values lie in \([0,1]\) and sum to 1. A probability says how confident the classifier is: 0.6 and 0.9 both lead to “class 1”, but only one of them is a confident call.

The Bayes classifier

Apply Bayes’ rule to the class label:

\[P(t_{\text{new}}=c\mid\mathbf{x}_{\text{new}},\ldots) = \frac{p(\mathbf{x}_{\text{new}}\mid t_{\text{new}}=c,\ldots)\,P(t_{\text{new}}=c\mid\ldots)} {\sum_{k=1}^{C} p(\mathbf{x}_{\text{new}}\mid t_{\text{new}}=k,\ldots)\,P(t_{\text{new}}=k\mid\ldots)} .\]

Naive Bayes. A full \(D\)-dimensional Gaussian has \(D + D(D+1)/2\) parameters, which needs a lot of data. Naive Bayes assumes that, given the class, the dimensions are independent, so the class-conditional is a product of \(D\) one-dimensional distributions: only \(2D\) parameters for Gaussians. The cost is flexibility: no dependence within a class can be modelled (for Gaussians, the contours are axis-aligned). The resulting probability contours are often still reasonable.

Text example (20 newsgroups). Represent a document with a bag of words: a vector of counts over the vocabulary (the word order is ignored). Use a multinomial class-conditional with naive Bayes over words. The maximum-likelihood word probabilities are the word’s share of all words in that class.

Smoothing. A word never seen in a class gets probability 0, which sends the whole document’s likelihood for that class to 0. Fix it by putting a Dirichlet prior on the word probabilities and using the MAP estimate. This adds a pseudo-count to every word, acts as regularisation, and gives a quite good classifier despite its simplicity. A plot of predicted probabilities by true class shows where errors cluster, often between closely related topics.

Logistic regression

Chapter 4’s model, now seen as classification. The sigmoid is formally justified by modelling the log-odds linearly:

\[\log\frac{P(t=1\mid\mathbf{x},\mathbf{w})}{P(t=0\mid\mathbf{x},\mathbf{w})} = \mathbf{w}^T\mathbf{x} \;\Longrightarrow\; P(t=1\mid\mathbf{x},\mathbf{w}) = \frac{1}{1+\exp(-\mathbf{w}^T\mathbf{x})}.\]

This is a generalised linear model: a linear model passed through a transformation. Adding terms such as \(x_1^2\), \(x_1x_2\) to \(\mathbf{x}\) gives curved decision boundaries, with the same over-fitting risk as high-order polynomials in Chapter 1.

Beyond parametric models (a mention)

A Gaussian process puts a prior directly on function values, with a mean function and a covariance function saying how similar the outputs at two inputs should be. It is nonparametric: no fixed parametric family for the function.

Non-probabilistic classifiers

They output a class label only.

K-nearest neighbours (KNN)

No training phase. For a new object, find the \(K\) closest training objects (any distance measure works) and take the majority class.

Support vector machines (SVM)

A binary classifier with a linear boundary, labels \(\{-1,+1\}\), decision rule \(\operatorname{sign}(\mathbf{w}^T\mathbf{x}_{\text{new}}+b)\). Choose \(\mathbf{w},b\) to maximise the margin: the distance from the boundary to the closest points of either class.

Assessing performance

Take predictions \(\hat t_n\) on test objects with true labels \(t_n^*\).

Generative and discriminative

Take-aways

  1. Probabilistic classifiers give class probabilities and confidence. Non-probabilistic ones give labels only.
  2. Bayes classifier: class-conditional densities times class priors. Naive Bayes trades flexibility for far fewer parameters, and smoothing stops zero counts from vetoing a class.
  3. Logistic regression models the log-odds linearly.
  4. KNN and SVM both need a complexity setting (\(K\); \(C\) and the kernel parameter) chosen by cross-validation.
  5. The SVM maximises the margin, depends only on the support vectors, and kernels give curved boundaries.
  6. Judge classifiers with measures suited to the task (sensitivity, specificity, AUC, confusion matrices), not only accuracy.