Sub topic 1
What Classification Asks of a Model
Prerequisites
This chapter assumes basic Python and NumPy, linear regression, loss functions, probability, derivatives, and train/test splits.
What Classification Asks of a Model
Classification predicts a discrete class, such as spam or not spam. A model can produce a class label directly, but it is often more useful to produce a probability first. For example, a spam classifier might assign an email a probability of 0.92 for the spam class. A decision rule then converts that probability into a label.
Why a Straight Line Is the Wrong Tool for Labels
Linear regression predicts an unrestricted number:
\[ s = x^\mathsf{T}w + b \]
This is a poor probability model because its predictions can be below 0 or above 1. Squared error also treats the distance between labels as meaningful. The difference between classes 0 and 1 does not mean that class 1 is “one unit” above class 0.
Logistic regression keeps the useful linear score but transforms it into a value between 0 and 1.
From Probability to Odds to Log-Odds
For a positive-class probability \(p\), the odds are:
\[ \text{odds} = \frac{p}{1-p} \]
Odds compare the chance of success with the chance of failure. Taking the natural logarithm gives the log-odds, also called the logit:
\[ \operatorname{logit}(p)=\log\left(\frac{p}{1-p}\right) \]
Logistic regression assumes that the log-odds are linear in the features:
\[ \log\left(\frac{p}{1-p}\right)=x^\mathsf{T}w+b \]
The Sigmoid: Turning a Score into a Probability
Solving the previous equation for \(p\) gives the sigmoid function:
\[ p=\sigma(s)=\frac{1}{1+e^{-s}} \]
A large positive score produces a probability near 1. A large negative score produces a probability near 0. A score of zero produces exactly 0.5.
Decision Boundaries and the 0.5 Threshold
With the usual threshold of 0.5, the model predicts class 1 when \(p \geq 0.5\). Because the sigmoid equals 0.5 when \(s=0\), this is equivalent to:
\[ x^\mathsf{T}w+b \geq 0 \]
The equation \(x^\mathsf{T}w+b=0\) defines the decision boundary. In two dimensions it is a line; in higher dimensions it is a hyperplane. A different threshold moves the boundary and changes the balance between false positives and false negatives.
Exercise
If a model's linear score is 2, is its predicted probability below or above 0.5?
Show answer
Above 0.5, because the sigmoid is above 0.5 for every positive score.