AI University
Statistics for Business

Logistic Regression

Understand probability. Explore classification. Make better business decisions.

Logistic regression estimates the probability of a categorical outcome — typically a binary one such as purchase or no purchase, customer churn or retention, late payment or on-time payment. Unlike linear regression, which predicts a continuous numerical outcome such as revenue or temperature, logistic regression answers a different kind of question: how likely is it that this event will happen?

Launch Interactive Simulation

Adjust the model, explore decision thresholds and watch logistic regression learn through interactive activities.

What You Will Learn

Learning Outcomes

By the end of this module you will be able to interpret predicted probabilities, calculate a linear score, understand the sigmoid function, apply classification thresholds, interpret a decision boundary, and evaluate model performance using standard metrics.

Interpret predicted probabilities from a logistic regression model
Calculate the linear score from model coefficients and input variables
Understand how the sigmoid function converts a score into a probability
Apply classification thresholds to convert probabilities into decisions
Interpret a decision boundary in a two-predictor space
Evaluate model performance using accuracy, precision, and recall
Section 1

Understanding Binary Outcomes

Imagine you run a subscription business. Each customer either purchases a subscription or they do not. In the language of logistic regression, we label a purchase as class 1 and a non-purchase as class 0. These are the observed outcomes — the ground truth recorded in your data.

The model does not simply predict class 1 or class 0 directly. Instead, it estimates a probability: the likelihood that a given customer belongs to class 1. For example, the model might estimate a 75% probability that a particular customer will purchase. That probability is then converted into a predicted class using a threshold you choose.

It is important to distinguish between these three things: the observed outcome (what actually happened), the estimated probability (what the model believes is likely), and the predicted class (the decision the model makes based on that probability). A predicted probability of 75% is an estimate, not a guarantee.

Section 2

Calculating the Linear Score

Before logistic regression can estimate a probability, it first calculates a linear score. This score, denoted z, is a weighted combination of the input variables.

z = β₀ + β₁x₁ + β₂x₂

The equation is: z = β₀ + β₁x₁ + β₂x₂. Here, β₀ is the intercept — a baseline value when all predictors are zero. The coefficients β₁ and β₂ describe how much each predictor contributes to the score. The variables x₁ and x₂ are the inputs — for example, a customer's engagement score and the number of recent website visits.

x₁ (engagement)× β₁x₂ (visits)× β₂β₀(intercept)Σ= zsigmoid(z)1/(1+e⁻ᶻ)pprobability

Predictors are multiplied by their coefficients, summed with the intercept, and passed to the sigmoid function.

Think of this as a recipe. Each ingredient (predictor) is multiplied by its own weight (coefficient), and the results are added together along with the intercept. The total is the linear score, which is then passed to the sigmoid function to produce a probability.

Section 3

The Sigmoid Function

The linear score z can range from negative infinity to positive infinity — it is not bounded between zero and one, so it cannot be used directly as a probability. The sigmoid function solves this by squashing any real number into the range (0, 1).

p = 1 / (1 + e⁻ᶻ)

The formula is: p = 1 / (1 + e⁻ᶻ). When z equals zero, the sigmoid returns exactly 0.50 — the model is completely uncertain. Positive values of z produce probabilities above 0.50, and negative values produce probabilities below 0.50. The further z is from zero, the closer the probability gets to 1 or 0.

1.00.50.0−50+5Linear score (z)Probability (p)(0, 0.5)

The sigmoid curve: linear score on the horizontal axis, predicted probability on the vertical axis. The curve passes through (0, 0.5) and flattens toward 0 and 1 at the extremes.

The resulting curve is S-shaped. It rises steeply in the middle and flattens at both ends. This flattening reflects the fact that once a score is very large or very small, additional changes have little effect on the probability — the model is already highly confident.

Section 4

A Worked Business Example

Consider a simplified model with one predictor — a customer's engagement score x. The model is: z = −3 + 0.8x. The intercept is −3 and the coefficient on engagement is 0.8. These are illustrative values chosen to make the arithmetic clear.

z = −3 + 0.8x

For a customer with an engagement score of x = 5, the linear score is: z = −3 + 0.8 × 5 = −3 + 4 = 1.

z = −3 + 0.8 × 5 = 1

Passing this score through the sigmoid function: p = 1 / (1 + e⁻¹) ≈ 0.731. The model estimates a 73.1% probability that this customer will purchase.

p = 1 / (1 + e⁻¹) ≈ 0.731

The probability of not purchasing is simply 1 − p = 1 − 0.731 = 0.269, or 26.9%. The two probabilities always sum to one. The model is telling us: given this customer's engagement level, a purchase is considerably more likely than not — but it is far from certain.

P(Y=0 | x) = 1 − p = 0.269

Teaching note

The model coefficients (−3 and 0.8) and the engagement score (x = 5) are illustrative examples chosen for clarity. They do not represent any real dataset.

Section 5

From Probability to a Decision

A probability on its own does not tell you what to do. To act on a logistic regression model, you need a classification threshold — a cut-off value t. If the estimated probability is at or above t, the model predicts class 1. If it falls below t, the model predicts class 0.

ŷ = 1 if p ≥ t, ŷ = 0 if p < t

Using the worked probability of 0.731: with a threshold of 0.50, the model predicts class 1 (purchase). With a threshold of 0.80, the model predicts class 0 (no purchase). The model's probability estimate has not changed — only the decision rule has.

Choosing the right threshold is a business decision, not a statistical one. Lowering the threshold means more customers receive an offer — you will reach more genuine buyers, but you will also send unnecessary offers to customers who would not have purchased anyway. Raising the threshold means you only target customers the model is very confident about, reducing wasted spend but potentially missing buyers.

0.30 — Broad targeting: more reach, more false positives
0.50 — Balanced: equal weight to false positives and false negatives
0.70 — Precise targeting: fewer false positives, risk of missing buyers
Section 6

Understanding the Decision Boundary

When a model uses two predictors — say, engagement score and recent website visits — you can visualise its decisions as a scatterplot. Each customer is a point, positioned by their two predictor values. The model assigns each point a probability, and the decision boundary is the line that separates the region where the model predicts class 1 from the region where it predicts class 0.

x₁ — Engagement scorex₂ — Website visitsDecision boundaryClass 1 — purchaseClass 0 — no purchase

A two-predictor scatterplot showing observed classes (circles and crosses) and the linear decision boundary separating the predicted regions.

At a threshold of 0.50, the boundary occurs exactly where the linear score equals zero: β₀ + β₁x₁ + β₂x₂ = 0. On one side of this line, the score is positive and the probability exceeds 0.50. On the other side, the score is negative and the probability falls below 0.50.

β₀ + β₁x₁ + β₂x₂ = 0

Standard logistic regression always produces a straight-line boundary in the predictor space. If the true boundary in your data is curved, you can introduce transformed predictors or interaction terms — but the model itself remains linear in those transformed inputs.

Section 7

How the Model Learns

A logistic regression model learns by repeatedly adjusting its coefficients to reduce prediction errors. The process begins with an initial guess for each coefficient. The model then calculates the linear score for every training example, converts each score into a probability using the sigmoid function, and measures how wrong those probabilities are.

L = −(1/n) Σ [ yᵢ ln(pᵢ) + (1−yᵢ) ln(1−pᵢ) ]

The measure of wrongness is called binary cross-entropy loss: L = −(1/n) Σ [yᵢ ln(pᵢ) + (1 − yᵢ) ln(1 − pᵢ)]. Here, n is the number of training examples, yᵢ is the observed class (0 or 1) for example i, and pᵢ is the model's estimated probability. Natural logarithms are used throughout.

The loss function penalises confident mistakes heavily. For an observed purchase (y = 1): if the model predicts p = 0.9, the loss contribution is −ln(0.9) ≈ 0.105 — a small penalty because the model was nearly right. If the model predicts p = 0.1, the loss contribution is −ln(0.1) ≈ 2.303 — a large penalty because the model was confidently wrong.

p = 0.9 → −ln(0.9) ≈ 0.105

Small penalty — the model was nearly correct.

p = 0.1 → −ln(0.1) ≈ 2.303

Large penalty — the model was confidently wrong.

After measuring the loss, an optimisation algorithm — typically gradient descent — nudges the coefficients in the direction that reduces the loss. This cycle of score, probability, loss, and update repeats until the loss stops improving meaningfully. The result is a set of coefficients that fit the training data as well as possible.

Training iterationsLossLoss converges

Loss decreases over training iterations as the model's coefficients improve.

Section 8

Evaluating Model Performance

Once a model is trained, you need to measure how well it performs. The starting point is the confusion matrix — a table that compares the model's predicted classes against the observed outcomes.

Predicted class
Predicted 1Predicted 0
Observed class
TP
True Positive
Obs 1, Pred 1
FN
False Negative
Obs 1, Pred 0
FP
False Positive
Obs 0, Pred 1
TN
True Negative
Obs 0, Pred 0

Confusion matrix: rows show observed classes, columns show predicted classes.

There are four possible outcomes. A true positive (TP) is a customer the model predicted would purchase, and they did. A true negative (TN) is a customer the model predicted would not purchase, and they did not. A false positive (FP) is a customer the model predicted would purchase, but they did not. A false negative (FN) is a customer the model predicted would not purchase, but they did.

From these four counts, three key metrics follow. Accuracy = (TP + TN) / (TP + TN + FP + FN) — the proportion of all predictions that were correct. Precision = TP / (TP + FP) — of all customers the model targeted, what fraction actually purchased? Recall = TP / (TP + FN) — of all customers who actually purchased, what fraction did the model identify?

Accuracy

(TP + TN) / Total

Overall proportion of correct predictions.

Precision

TP / (TP + FP)

Of those targeted, how many actually purchased?

Recall

TP / (TP + FN)

Of all buyers, how many did the model identify?

A worked example: if the model targets 40 customers and 30 of them actually purchase, precision is 30/40 = 75%. Accuracy can be misleading when one class is much more common than the other — a model that always predicts the majority class can achieve high accuracy while being completely useless. Precision and recall give a clearer picture in those situations.

Finally, model development requires three separate data splits. Training data is used to fit the coefficients. Validation data is used to tune the threshold and other model settings. Test data is held back entirely and used only for the final performance evaluation. Evaluating on training data alone produces an overly optimistic picture of how the model will perform on new customers.

Section 9

Interpreting Coefficients

The coefficients in a logistic regression model do not describe changes in probability directly. Instead, they describe changes in log-odds. The log-odds of an event is the natural logarithm of the ratio of the probability of the event to the probability of its complement: ln(p / (1 − p)) = β₀ + β₁x.

ln(p / (1−p)) = β₀ + β₁x

To interpret a coefficient in more intuitive terms, exponentiate it: odds ratio = e^β₁. This tells you how the odds of the outcome change for a one-unit increase in the predictor, holding all other predictors constant.

Odds ratio = e^β₁

For example, if β₁ = ln(2) ≈ 0.693, then e^β₁ = 2. A one-unit increase in the predictor doubles the odds of purchasing. This does not mean the probability doubles — the relationship between odds and probability is non-linear. A doubling of odds from 1:1 (50% probability) takes you to 2:1 (67% probability), while a doubling from 9:1 (90% probability) takes you to 18:1 (95% probability).

One further caution: a statistically significant coefficient tells you that a predictor is associated with the outcome in your data. It does not establish that the predictor causes the outcome. Confounding variables, selection effects, and data artefacts can all produce associations that do not reflect genuine causal relationships.

Section 10

More Than Two Classes

Standard logistic regression handles binary outcomes — two classes. When the outcome has three or more categories, the approach extends to multinomial logistic regression.

Imagine your subscription business offers three tiers: Basic, Plus, and Premium. A customer will choose exactly one. Multinomial logistic regression fits a separate linear score for each class, then uses the softmax function to convert those scores into probabilities that sum to one: P(Y = k | x) = e^zₖ / Σⱼ e^zⱼ.

P(Y=k | x) = e^zₖ / Σⱼ e^zⱼ
0%25%50%18%Basic47%Plus35%PremiumProbabilities sum to 100%

Softmax output: three mutually exclusive subscription tiers with probabilities that sum to 1.

The softmax function ensures that the predicted probabilities across all classes are non-negative and sum to exactly one — a requirement for a valid probability distribution over mutually exclusive outcomes. The class with the highest predicted probability becomes the predicted class, unless a different decision rule is applied.

Try It Yourself

Apply What You Have Learned

Open the interactive simulation and work through the following activities. Each one is designed to build your intuition for how logistic regression behaves in practice.

1
Adjust the intercept and coefficient and observe how the predicted probability changes for a fixed input value.
2
Compare thresholds of 0.30 and 0.70 and note how the confusion matrix changes.
3
Find the threshold that maximises precision. Then find the threshold that maximises recall. Explain the trade-off.
4
Inspect the decision boundary as you change the coefficients. When does the boundary shift left or right?
5
Observe the loss curve during training. At what point does the loss stop decreasing significantly?
FAQ

Frequently Asked Questions

Linear regression predicts a continuous numerical outcome, such as revenue or temperature. Logistic regression predicts the probability of a categorical outcome — most commonly a binary one such as purchase or no purchase. The key difference is the sigmoid function: logistic regression passes its linear score through the sigmoid to produce a probability bounded between zero and one, whereas linear regression outputs the score directly.

Linear regression can produce predicted values below zero or above one, which are not valid probabilities. It also assumes that the relationship between the predictor and the outcome is linear across the entire range, which is rarely true for binary outcomes. Logistic regression avoids both problems by modelling the log-odds rather than the probability directly, and by using the sigmoid function to constrain predictions to the (0, 1) interval.

The right threshold depends on the business consequences of false positives and false negatives. If missing a genuine buyer (false negative) is more costly than sending an unnecessary offer (false positive), lower the threshold to increase recall. If wasted spend on non-buyers is the bigger concern, raise the threshold to improve precision. There is no universally correct threshold — it is a business decision that should be informed by the cost of each type of error.

A coefficient represents the change in the log-odds of the outcome for a one-unit increase in the corresponding predictor, holding all other predictors constant. To interpret it more intuitively, exponentiate the coefficient to get the odds ratio. An odds ratio of 2 means a one-unit increase in the predictor doubles the odds of the outcome. Remember that this is an association, not a causal claim, and that a change in odds does not translate to a proportional change in probability.

Use multinomial logistic regression when the outcome has three or more mutually exclusive categories — for example, choosing between Basic, Plus, and Premium subscription tiers. Standard binary logistic regression handles only two classes. Multinomial logistic regression fits a separate linear score for each class and uses the softmax function to convert those scores into probabilities that sum to one across all classes.

Ready to Enrol?

Continue Your Statistics for Business Journey

This module is part of the Statistics for Business short course at AI University. Explore the full curriculum, including probability, sampling, hypothesis testing, and applied analytics projects.