Lecture 4: Perceptron and Generalized Linear Models
Stanford CS229 lecture 4 notes: Perceptron and Generalized Linear Models.
- cs229
- machine-learning
- course-notes
On this page
The Perceptron#
Take logistic regression, but replace the smooth sigmoid with a hard threshold:
with . The update rule looks the same as before:
What does this do?
- If the prediction is right, , so nothing changes.
- If it predicts 0 but the answer is 1, , so we add to (rotate the boundary towards classifying that point as 1).
- If it predicts 1 but the answer is 0, we subtract.
The perceptron has no probabilistic interpretation. It just says 0 or 1, with nothing about how confident it is. That's one reason it isn't used much today, but it was historically important for neural nets.
The Exponential Family#
Here's something that ties linear regression and logistic regression together. A distribution is in the exponential family if it can be written as:
- = natural parameter
- = sufficient statistic (usually just )
- = log partition function (makes it normalize to 1)
Lots of distributions fit this: Gaussian, Bernoulli, Poisson, Gamma, Beta, Dirichlet...
Example: Bernoulli with parameter . We get . Invert it and you get , the sigmoid! That's where it comes from.
Generalized Linear Models (GLMs)#
A GLM is a recipe. Say you want to model given . Make three assumptions:
- The prediction is
- The natural parameter is linear in the inputs:
Plug in different distributions, and you get different models:
| If is... | Distribution | Model |
|---|---|---|
| real valued | Gaussian | Linear regression |
| 0 or 1 | Bernoulli | Logistic regression |
| a count (0, 1, 2, ...) | Poisson | Poisson regression |
| positive real | Gamma / Exponential | Gamma regression |
And the cool part: for every GLM, the learning rule is the same gradient ascent update we've been seeing:
That's why logistic regression's update matched linear regression's.
Softmax Regression#
What if can be one of classes (dog, cat, bird...)? This is a multinomial distribution, which is also in the exponential family. The GLM recipe gives:
This is softmax. It turns scores into probabilities that add up to 1. We train it by maximizing the log likelihood, same as before. You'll see this at the end of every classification neural net.