esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
Let’s talk

I’ll build the agent for it.

What Is Logistic Regression?

How logistic regression turns a few facts into a probability, where banks use it, and how to explain it, for your AI interview.

In short

Logistic regression is a classic model that predicts the probability of a yes or no outcome, such as whether a card payment is fraud. It adds up weighted facts, then a sigmoid function squeezes the result between 0 and 1, so the output reads as a chance.

11 min readBeginnerCommon · estimateFacts checked 27 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

Logistic regression is a simple, classic model that gives a probability for a yes or no question. Take a card payment: the model weighs the amount, the device and the country, adds them up, and squeezes the result into a number between 0 and 1. That number is the chance of fraud. Despite its name, it is a classifier: it sorts payments into groups. It is a good first model to try, because it is an extremely efficient mechanism for calculating probabilities.

What is logistic regression, in plain words?

Logistic regression is a model that answers a yes or no question with a chance, such as the chance that a card payment is fraud. Despite its name, in scikit-learn and ML terms it is a linear model for classification, which means sorting things into groups.

  • Linear regression

    Predicts a number

    For example, the delivery time of an order in days. The answer can be any number.

  • Logistic regression

    Predicts a chance

    For example, the chance that a card payment is fraud. The answer always sits between 0 and 1.

Think of a fraud clerk at a bank. She looks at a card payment and weighs a few facts: is the amount far above the customer's usual spend, is the phone new to the account, is the card being used abroad? Each fact nudges her gut feeling up or down a little. Logistic regression does the same weighing with numbers, then turns the total into one chance. A bank's scoring system runs that sum for every card payment, using weights learned from past payments that were already marked fraud or genuine.

Key words

Probability
A number from 0 to 1. 0.93 means a 93% chance.
Sigmoid function
An S-shaped curve that squeezes any number into a value between 0 and 1.
Log-odds
The raw score the model adds up before the squeeze. Also called z.
Threshold
The cut-off that turns a probability into a decision, 0.5 by default in scikit-learn.

How does it turn signals into a chance?

Every input goes through three steps.

  1. 1

    Weigh each signal

    Each fact is multiplied by its weight. A bigger weight moves the answer more.

  2. 2

    Add them up

    The weighted facts and a starting number called the bias make one score, the log-odds.

  3. 3

    Squeeze to a chance

    The sigmoid function turns the score into a value from 0 to 1, which we read as a probability.

How a card payment gets a chance of fraud

Facts about the payment

Amount far above usual

weight 2.2 in our sketch

New device on account

weight 1.8 in our sketch

Card used abroad

weight 1.5 in our sketch

Add weighted signals

gives the log-odds score z

Sigmoid squeeze

turns z into a chance from 0 to 1

Approve

chance below the threshold

Hold for review

chance at or above the threshold

  1. 1The amount signal goes in, multiplied by its weight.
  2. 2The new device signal goes in, multiplied by its weight.
  3. 3The card-abroad signal goes in, multiplied by its weight.
  4. 4The weighted signals and the bias make one score, z.
  5. 5The sigmoid turns z into a chance. A low chance is approved.
  6. 6A high chance, at or above the threshold, is held for review.
Each fact about a payment carries a weight. The model adds them into one score, and the sigmoid turns that score into a chance. The threshold then decides whether the payment is approved or held. The weights in this picture are made up.

The sigmoid curve is what makes the output a probability. Very negative scores give a chance near 0, and very positive scores give a chance near 1. A few readings make it concrete:

  • Score 0

    A 50% chance.

  • Score 2

    About 88%.

  • Score -2

    About 12%.

  • Any score

    Never exactly 0% or 100%, however large or small the score.

Tip

Say that the output is a probability. The yes or no comes later, from a threshold you choose.

With more than two classes, scikit-learn uses the softmax function instead. It gives one probability for each class.

How is it trained, and why not squared loss?

A model learns its weights from past examples whose answers are already known, such as payments marked fraud or genuine. For each example it guesses a chance, measures how wrong the guess was, and moves the weights to do better next time.

How a logistic model learns its weights

Past payments with answers

fraud or genuine, already known

Model guesses a chance

for each past payment

Log loss scores the miss

wrong and confident costs most

Weights nudged

a small step towards better

Ready to score

new payments get a chance

  1. 1Past payments, with the true answer, teach the model.
  2. 2The model guesses a chance for each one.
  3. 3Log loss measures how far off each guess was.
  4. 4After many small steps the weights settle, and the model is ready.
The model learns from past payments whose answers are known. Each guess is scored with log loss, and the weights move to shrink the error. Over many examples, the weights settle into a model that can score new payments.

Linear regression usually measures error with squared loss. Logistic regression does not suit it well, because the sigmoid curve is s-shaped rather than linear, so the same change in the score moves the chance by different amounts. Log loss fits that curve better. It punishes a confident wrong guess hard: saying 2% fraud for a payment that was fraud costs far more than saying 40%.

  • “Logistic regression models use Log Loss as the loss function instead of squared loss.”

    Google Machine Learning Crash Course

Training also needs regularization, a penalty that stops the weights growing too large. Without it, the model can memorise its history and miss new payments. This is overfitting. Google's crash course calls regularization critical here, and scikit-learn applies it by default.

Can you run the fraud example by hand?

Here are three card payments. The weights are made up for this sketch: amount far above usual 2.2, new device 1.8, card abroad 1.5, and a bias of -4. A real bank learns its weights from past data.

A usual grocery payment has no warning signs, so the score is -4 and the chance is 1.8%. A new phone with the card abroad gives a score of -0.7 and a 33.2% chance. That is below a 0.5 threshold, so it is approved. A large payment from a new phone, abroad, gives a score of 1.5 and an 81.8% chance, so it goes to review.

Python
import math

# Made-up weights for a card-payment fraud score. A real model learns them from past payments.
WEIGHTS = {"amount_vs_usual": 2.2, "new_device": 1.8, "card_abroad": 1.5}
BIAS = -4.0

def fraud_probability(signals):
    # z is the log-odds: each signal times its weight, added up, plus the bias.
    z = BIAS + sum(WEIGHTS[name] * value for name, value in signals.items())
    # The sigmoid turns z into a probability between 0 and 1.
    return 1 / (1 + math.exp(-z))

payments = {
    "Usual grocery payment": {"amount_vs_usual": 0, "new_device": 0, "card_abroad": 0},
    "New phone, card abroad": {"amount_vs_usual": 0, "new_device": 1, "card_abroad": 1},
    "Large, new phone, abroad": {"amount_vs_usual": 1, "new_device": 1, "card_abroad": 1},
}

for name, signals in payments.items():
    p = fraud_probability(signals)
    action = "hold for review" if p >= 0.5 else "approve"
    print(f"{name}: {p:.1%} fraud chance, {action}")

Output

Usual grocery payment: 1.8% fraud chance, approve
New phone, card abroad: 33.2% fraud chance, approve
Large, new phone, abroad: 81.8% fraud chance, hold for review

The code is only a sketch. It shows the three steps, and the last check decides the action.

How would you pick the threshold for a fraud model?

The 0.5 cut-off is only the default. The threshold is a business choice, because each mistake costs something different. Missed fraud loses money. A blocked genuine payment annoys a customer, who may leave.

  • Lower, say 0.3

    More fraud caught

    But more genuine payments are blocked, and the call centre gets more complaints.

  • Higher, say 0.8

    Fewer false alarms

    But more fraud gets through, and the bank pays for it.

A sensible way to choose: test a few thresholds on past payments, count the missed fraud and the blocked genuine payments at each one, and agree the balance with the risk team. Check it again when fraud patterns change.

What does the interviewer want to hear?

A strong answer covers

  • A plain definition: a model that gives the probability of a yes or no outcome.
  • The sigmoid: it squeezes a score into a value between 0 and 1.
  • Why it is called regression but used for classification.
  • Log loss for training, and regularization against overfitting.
  • The threshold is a choice that depends on the cost of each kind of mistake.
  • A real case, such as fraud or loan default, and why it is a good first model.

Common traps

  • Trap"It predicts a yes or no answer."

    BetterIt predicts a probability. A threshold turns that probability into yes or no.

  • Trap"Its name says regression, so it predicts numbers."

    BetterIt is a classifier. Its output is a chance between 0 and 1, such as 0.93 for a likely fraud.

  • Trap"Use 0.5 as the cut-off, it is always right."

    Better0.5 is only the default. Pick the threshold from the cost of missed fraud against blocked payments.

Can you spot the mistake?

Spot the mistake

A junior analyst wrote four notes about a fraud model. Which note is wrong?

Quick check

A fraud model gives 0.4 to a payment that turns out to be fraud. The threshold is 0.5. What happens?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q430What is a confusion matrix?10 min
  2. Q437Softmax vs sigmoid?12 min
  3. Q429What is early stopping?10 min
  4. Q436How do you tune hyperparameters?10 min
  5. Q412Bias vs variance?12 min

Learn it in depth

Last updated on 27 November 2026

Building a model that flags risky payments or loan applications?

I design and build AI products and agents, including the interface and the system behind it. Book a short call and tell me what decision your model has to make.