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
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

MSE vs Cross-Entropy Loss

Mean squared error or cross-entropy: which loss fits a number and which fits a probability, and why it matters, for your AI interview.

In short

Use mean squared error (MSE) when a model predicts a number, such as a house price. Use cross-entropy, also called log loss, when it predicts a probability, such as fraud or not, because it punishes confident wrong answers much harder.

11 min readIntermediateVery common · estimateFacts checked 26 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.

MSE is for predicting a number, like a house price. It averages the squared gaps between guesses and truth, so big misses hurt a lot. Cross-entropy is for predicting a probability, like fraud or not. It punishes a confident wrong answer much harder than squared error does. So I pick the loss from the output: numbers get MSE, probabilities get cross-entropy.

What are MSE and cross-entropy, in plain words?

A loss function is a score for how wrong a model's answer was. Training changes the model so that score goes down. The loss you pick decides which mistakes the model learns to fix first.

Mean squared error (MSE) is the average of the squared gaps between each guess and the true value. Cross-entropy, also called log loss, is for a model that gives a probability, such as the chance a card payment is fraud. It asks how much probability the model gave to the true answer.

Think of two claims adjusters at an insurer. One estimates the repair bill for a flood-hit flat, which is a number. The other decides whether a claim is fraud, which is a probability. Each needs its own way of being scored.

So a model that predicts a number gets MSE. A model that predicts a probability gets cross-entropy. A bank's card fraud model is the probability case.

Key words

Loss function
The score for one wrong answer. Training pushes it down.
Label
The true answer in your data, such as 1 for fraud and 0 for not fraud.
Probability
A number from 0 to 1. 0.93 means the model is 93% sure.
Logit
The raw score a model makes before it turns into a probability.

What does MSE do, and where does it go wrong?

MSE takes each guess, subtracts the true value, squares the gap, and averages those squares. Squaring makes a big miss count far more than a small one. That is useful when big misses are costly.

Worked example, with made-up numbers. A valuation model for a mid-size city guesses 2.4 million for a mansion that sold for 1.5 million. The gap is 900,000, and its square is 810 billion. A flat that is 10,000 off adds only 100 million. So one mansion miss counts as much as 8,100 small flat misses, and training bends toward it.

  • “MSE moves the model more toward the outliers, while MAE doesn't.”

    Google, machine learning crash course

  • “Choose MSE: If you want to heavily penalize large errors.”

    Google, machine learning crash course

The result is in squared units, so a price error becomes dollars squared. Take the square root, called RMSE, to get back to dollars.

Tip

Asked which loss for a price model? Say MSE, then name its weak spot: one huge miss can drag the whole model. Add that you would check the data for outliers first.

What does cross-entropy do, and why is it for probabilities?

Cross-entropy scores a probability by taking the log of the chance the model gave to the true answer, then flipping the sign so the score is positive. If the true answer got a tiny chance, the log is very negative, so the score is large.

  • “Log loss, aka logistic loss or cross-entropy loss.”

    scikit-learn documentation

  • “This is the loss function used in (multinomial) logistic regression and extensions of it such as neural networks”

    scikit-learn documentation

It is the loss used in multinomial logistic regression and in extensions of it, such as neural networks. In PyTorch, a popular AI library for Python, CrossEntropyLoss expects unnormalised logits, the raw scores before any probability step, and it applies the softmax step itself. Softmax rescales scores so they lie between 0 and 1 and add up to 1.

Here is a made-up fraud model at a bank. For a payment that really was fraud, it gives only a 1% chance of fraud. The code below scores that one miss and shows how hard each loss pushes the model. Here 'push' means how much one example changes the model's raw score during training. The demo assumes the model turns that raw score into a probability with a sigmoid, an S-shaped step. It uses only Python's standard library.

Python
# A made-up fraud model at a bank. Label 1 means the payment really was fraud.
# The model's probability of fraud is p. We check the loss and the push on each step.
import math

def mse(p, y):
    return (p - y) ** 2

def cross_entropy(p, y):
    return -(y * math.log(p) + (1 - y) * math.log(1 - p))

def push_mse(p, y):
    # MSE's push passes through the sigmoid's slope, p * (1 - p), so it shrinks when p is near 0 or 1
    return 2 * (p - y) * p * (1 - p)

def push_ce(p, y):
    return p - y

y = 1  # the payment really was fraud
for p in (0.01, 0.5, 0.9):
    print(f"model says {p:.0%} fraud, truth is fraud")
    print(f"  loss: MSE {mse(p, y):.3f}, cross-entropy {cross_entropy(p, y):.3f}")
    print(f"  push: MSE {push_mse(p, y):+.4f}, cross-entropy {push_ce(p, y):+.2f}")

Output

model says 1% fraud, truth is fraud
  loss: MSE 0.980, cross-entropy 4.605
  push: MSE -0.0196, cross-entropy -0.99
model says 50% fraud, truth is fraud
  loss: MSE 0.250, cross-entropy 0.693
  push: MSE -0.2500, cross-entropy -0.50
model says 90% fraud, truth is fraud
  loss: MSE 0.010, cross-entropy 0.105
  push: MSE -0.0180, cross-entropy -0.10

One confident miss, two pushes

Fraud model

Says 1% fraud, but it is fraud

Squared gap (MSE)

Weak push

Push about 0.02 on this miss

Log loss (cross-entropy)

Strong push

Push about 0.99 on this miss

Model learns the miss

Size of the push differs

  1. 1The squared gap gives a small push on this miss.
  2. 2Log loss gives a large push on the same miss.
  3. 3The small push means slower learning from this miss.
  4. 4The large push means faster learning from this miss.
The same confident miss on a fraud model, scored two ways. The squared gap gives a weak push and log loss gives a strong one. The push numbers come from the small made-up example above.

The numbers show the gap. In the demo, MSE's push on this confident miss is about 50 times weaker than cross-entropy's. With a sigmoid output, the squared gap gives a small push when the model is very sure, so it learns slowly from its worst misses.

Which loss should you pick, and what are the limits?

Pick by the output first, then ask what a miss costs. A number gets MSE and a probability gets cross-entropy. Training lowers whichever score you chose.

Pick the loss by the output

Predicts a number

For example a house price

Predicts a probability

For example fraud or not

MSE

Average of squared gaps

Cross-entropy

Minus log of true-answer chance

Lower loss, better fit

Training pushes the score down

  1. 1A number gets the squared gap between guess and truth.
  2. 2A probability gets the log of the chance given to the true answer.
  3. 3Training lowers the MSE score.
  4. 4Training lowers the cross-entropy score.
Start from what the model outputs. A number goes to MSE, a probability goes to cross-entropy, and training lowers the score you chose.
  • Use MSE

    A number, like a price

    Averages the squared gaps. Big misses cost more, so outliers can pull the model.

  • Use cross-entropy

    A probability, like fraud

    Scores the chance given to the true answer. A confident miss gets a big penalty.

  • Check first

    Your labels

    Both losses trust the labels. A wrong fraud label can cost a lot, so clean them first.

Neither loss fixes a wrong target. If the business cares most about rare fraud, check the scores on the fraud cases, not only the average loss.

What does the interviewer want to hear?

A strong answer covers

  • Pick the loss from the output: a number gets MSE, a probability gets cross-entropy.
  • MSE is the average of squared gaps, and big misses weigh heavily.
  • Cross-entropy is the log of the chance given to the true answer.
  • Why it punishes confident wrong answers harder, with a number.
  • PyTorch's CrossEntropyLoss expects raw logits, not probabilities.
  • Clean labels matter, because the loss trusts them.

Common traps

  • Trap"MSE is always the safe default."

    BetterIt is safe for numbers. For probabilities it pushes weakly on confident misses, the cases that hurt most.

  • Trap"Cross-entropy works on any output."

    BetterIt needs probabilities, or raw logits in PyTorch. A price is the wrong fit.

  • Trap"Log loss and cross-entropy are two different losses."

    BetterSame idea here. Scikit-learn calls it log loss, aka cross-entropy.

Can you spot the wrong pairing?

Spot the wrong pairing

Which of these pairs a loss with the wrong kind of output?

Quick check

A bank's model outputs the chance that a card payment is fraud. Which loss fits best?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q415What is gradient descent?12 min
  2. Q418What is backpropagation?11 min
  3. Q417What does the learning rate do?Coming soon
  4. Q420Precision, recall and F1?10 min
  5. Q414L1, L2 and dropout regularisation?13 min
  6. Q416SGD vs Adam?Coming soon

Learn it in depth

Last updated on 26 November 2026

Building a model that predicts prices or fraud risk?

I design and build AI products and agents, including the system behind the screen. Book a short call and tell me what your model predicts and what a miss costs you.