Logistic RegressionIntroduction
In the last chapter, we taught our computer how to predict continuous numbers (like the exact price of a house or someone's height) using Linear Regression. But what if we don't want a number? What if we want a concrete "Yes" or "No" answer?
Welcome to the world of Classification! In this chapter, we will learn about Logistic Regression, which is a method designed specifically to classify data into categories.
Most of the time, we use this for binary classification—meaning we are choosing between exactly:
The Problem with Straight Lines
To choose between two groups (let's call them
If you remember from math class, what is the absolute range of any true probability? (e.g. "There is a 75% chance of rain").
Prompt: A minimal artistic graphic showing a straight line aggressively shooting off to infinity, but being squashed by a boundary box labeled '0' and '1'.
If we used a straight line (our old friend
The Sigmoid "S" Curve
To solve this, we use a neat mathematical trick called the Sigmoid function. It takes a normal straight line and bends it into a beautiful "S" shape.
The Concept
Instead of predicting an exact number, the "S" curve outputs a percentage. If the output is
The Mathematics
For the mathematically curious!
First, we calculate our standard straight line (our "linear predictor"), exactly like we did in the last chapter:
Then, instead of making
Now, the output represents the exact probability of our event happening!