No history yet

Introduction to Logistic Regression

Predicting Yes or No

Linear regression is great for predicting a number that can go up or down, like the price of a house or the temperature tomorrow. But what if the question you want to answer is a simple yes or no? Will a customer click on an ad? Is this email spam? Will a patient respond to a certain treatment?

These are binary questions—they have only two possible outcomes. Trying to fit a straight line through yes/no data doesn't work well. A line can shoot off past 100% or dip below 0%, which makes no sense when you're talking about the chance of something happening. We need a model that's built for this kind of problem. That's where logistic regression comes in.

Logistic regression predicts the probability that an event will occur. The output is always a number between 0 and 1, representing a 0% to 100% chance.

Instead of predicting a value directly, it models the likelihood of a specific outcome. This makes it one of the most fundamental tools for classification tasks in machine learning.

The S-Curve

To keep its predictions between 0 and 1, logistic regression uses a special mathematical function called the logistic function, also known as the sigmoid function. It takes any number, from negative infinity to positive infinity, and squishes it into a value between 0 and 1.

The result is a gentle S-shaped curve. At the low end, the probability is close to 0. As the input increases, the probability smoothly climbs, passing 0.5 (or 50%) at the midpoint. At the high end, it gets very close to 1.

Think of it like this: an email security system might analyze different factors, like the number of capitalized words or the presence of suspicious links. Logistic regression combines these factors into a single score. If the score is very low, the probability of spam is near zero. If it's very high, the probability is near one. The curve ensures the prediction is always a valid probability.

Odds, Not Values

So how does logistic regression connect a straight line to this S-curve? It does so through a clever trick involving odds.

In statistics, odds are a way of representing probability. The odds of an event are the ratio of the probability it will happen to the probability it won't.

Odds=p1pOdds = \frac{p}{1-p}

Here's the key idea: logistic regression creates a linear model to predict the logarithm of the odds (also called the logit). This log-odds value can be any number, just like the output of a linear regression. The model then uses the logistic function to convert this log-odds value back into a simple probability between 0 and 1.

This is the core difference between linear and logistic regression.

FeatureLinear RegressionLogistic Regression
OutputA continuous number (e.g., 42.7)A probability between 0 and 1
RelationshipModels a linear relationshipModels probability using a logistic curve
Use CasePredicting values (e.g., price)Classification (e.g., spam/not spam)

Where It's Used

Because it's straightforward and effective, logistic regression is used across many fields.

  • Medicine: Predicting if a tumor is malignant or benign based on medical imaging data.
  • Finance: Determining whether a customer will default on a loan based on their credit history and income.
  • Marketing: Forecasting if a user will click an online ad or subscribe to a service.
  • Spam Detection: Classifying an email as spam or not based on its content and sender.

If your primary goal is to understand the fundamental drivers of churn to inform your product roadmap or overall strategy, a transparent model like Logistic Regression is a fantastic place to start.

Time to test what you've learned.

Quiz Questions 1/4

What is the primary reason for using logistic regression for binary classification problems instead of linear regression?

Quiz Questions 2/4

What is the main purpose of the sigmoid (logistic) function in a logistic regression model?

Logistic regression provides a solid foundation for understanding more complex classification models. It's a powerful and interpretable tool for tackling any problem that requires a 'yes' or 'no' answer.