MIT 6.790 — Lecture 8
Classification and Logistic Regression
§ Classification
Over the past few lectures on linear regression, we've assumed that the output space is . In classification problems, we instead take to be discrete; for now, let's further assume is binary, meaning .
This is the setup for logistic regression, covered in Lecture 25 of 18.650. These notes will assume knowledge of that lecture.
§ Bayes Classifier
Here's the most common choice of loss function for (binary) classification problems.
Definition. The zero-one loss is . The loss equals zero if the classification was right, and one otherwise.
In this case, it's clear that the best classifier is the Bayes classifier.
Theorem. (Bayes Classifier) The best (lowest-risk) classifier under zero-one loss is:
Of course, the challenge is that we don't know what the distribution exactly looks like.
§ Nearest Neighbor Classifier
Here's a simple design of a binary classifier.
Definition. Given an input space , impose some distance metric . Then predict the label like so:
Identify the set of the indices of the training points closest to . Then return .
This is called the nearest neighbor classifier (or NN, or KNN). It's simple, but slow: making a single prediction requires scanning the entire training set.
§ ERM: Linear Classifier
Let's try an ERM approach instead; here's the set of hypotheses we'll restrict ourselves to.
Definition. A linear classifier is a map via , for some parameter .
Remark. We'll often pad every vector in with an extra one, as usual; recall Lecture 24 of 18.650.
Then ERM tells us we should choose to minimize the empirical risk , given below:
Note that is just a one-variable form of zero-one loss. Unfortunately, the empirical risk described above is hard to optimize (via gradient descent, say) because is not convex or differentiable. Here's a better alternative:
Definition. A convex variant of zero-one loss is logistic loss, given by .

§ Addendum: Convexity
We provide a brief reminder of convexity here; it's important to know for optimization purposes.
Definition. A twice-differentiable function is convex if any of the following (equivalent) statements is true.
We have for all ; that is, is positive semidefinite.
Note that here is the Hessian, which is the matrix given by .
We have for all and .
That is, any line segment connecting two points on the graph of lies above the graph.
We have for all .
That is, the tangent plane to at lives underneath the graph of everywhere.
Here's why we care about convexity so much:
Theorem. (Local = Global) For any convex objective over a convex domain, any local minimum is a global minimum.
So techniques that seek out local minima (e.g., gradient descent) are really seeking out the global minimum. You can check that logistic loss is convex.
§ MLE: Logistic Regression
As in Lecture 25, we'll switch our hypothesis to be a map , where the goal is to have be a solid approximation of . Then our classification model is , naturally.
Specifically, we'll assume that takes the form , where is the sigmoid function.
Theorem. (Logistic Loss) The log (base 2) likelihood of is:
The term is called the margin, whose sign determines correctness and whose magnitude determines confidence.
The proof is just plain computation, so we omit it. Note that this differs slightly from the result in Lecture 25 of 18.650 because of the convention that instead of .
The interesting part is the coincidence that logistic loss shows up once again. The following are therefore identical:
Maximizing the likelihood, given a model designed to approximate .
Minimizing the logistic loss, given a hypothesis designed to predict the classification of .
§ Addendum: Log-Odds and Linear-Logistic Equivalence
Definition. The log-odds is defined as the value .
Theorem. (Linear-Logistic Equivalence) Given a classification model, consider the following two procedures.
Logistic regression, seeking a parameter for which equals the probability .
Linear regression, seeking a parameter for which equals the log-odds .
Then the two procedures seek the same parameter: .
Proof: Obvious; the log-odds function is just the inverse of , in that .
So all of the discussion about features and kernels concerning linear regression applies equally well to logistic regression.