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.
A loss function is the score a model gets for each wrong answer. Training changes the model so that score goes down. The score I choose decides which mistakes the model learns to fix first, so the first question is always what the model outputs.
If it outputs a number, like the price of a house, I use mean squared error. For each house I take the gap between the guess and the real price, square it, and average the squares. Squaring means one badly wrong mansion valuation counts far more than many small misses. That helps when big misses are costly, and it is a trap when one outlier, a very unusual value far from the rest, can drag the whole model.
If it outputs a probability, like fraud at 93%, I use cross-entropy, also called log loss. It takes the log of the probability the model gave to the true answer. If the model said 1% fraud on a payment that was fraud, the penalty is large, about 4.6 in my small made-up example. With a sigmoid output (the S-shaped step that turns a score into a probability), the squared-error push on that same miss is about fifty times weaker.
In PyTorch, a popular AI library for Python, CrossEntropyLoss takes raw scores called logits and applies the softmax step itself. So I pick the loss from the output, check the numbers on a few made-up cases, and ask what a miss costs the business.
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.
# 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
- 1The squared gap gives a small push on this miss.
- 2Log loss gives a large push on the same miss.
- 3The small push means slower learning from this miss.
- 4The large push means faster learning from this miss.
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
- 1A number gets the squared gap between guess and truth.
- 2A probability gets the log of the chance given to the true answer.
- 3Training lowers the MSE score.
- 4Training lowers the cross-entropy score.
- 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
What will they ask next?
- Q415What is gradient descent?12 min
- Q418What is backpropagation?11 min
- Q417What does the learning rate do?Coming soon
- Q420Precision, recall and F1?10 min
- Q414L1, L2 and dropout regularisation?13 min
- 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.