The mean squared error (MSE) is the single most common way to measure how wrong a regression model is. It takes the gap between each prediction and the true value, squares it, and averages the result across every example. That one design choice — squaring — is what gives the MSE its personality: it is smooth, easy to optimise, and unforgiving of large mistakes. If you fit a straight line, train a neural network on a continuous target, or compare two forecasts, the MSE is almost always the number you are minimising, whether you realise it or not.

What is the MSE?
The mean squared error answers a simple question: on average, how far are my predictions from the truth, and how much should big misses count? For every data point you take the residual — the predicted value minus the actual value — square it so that positive and negative errors do not cancel out, and then average those squares over the whole dataset. Because the errors are squared, the MSE is always positive, it is measured in the square of the target’s units, and a prediction that is twice as far off contributes four times as much to the total. That last property is the heart of the metric: the MSE cares far more about a few large errors than about many small ones.
It shows up under many names. Statisticians call it the MSE; machine-learning engineers often call it the squared loss or L2 loss; and when you take its square root you get the root mean squared error, which is easier to interpret. They are all built from the same squared residuals.
The mean squared error formula
Here n is the number of examples, yi is the true value, and ŷi is the model’s prediction. Read it left to right: take each error, square it, add them all up, and divide by how many there are. The mean squared error formula is deliberately plain — there is nothing to tune inside it, which is part of why it has been the default regression loss for over a century.
See it: how the MSE grows
The blue curve below is the loss contributed by a single prediction as its error moves away from zero; the orange dashed line is the gradient (how hard the loss pushes back). Notice the loss is a parabola — it rises slowly near zero and then steeply, which is the squaring at work.
A worked example
Suppose a model predicts house prices (in $1,000s) for three homes. The true values are 200, 250 and 300; the predictions are 210, 230 and 340. The residuals are −10, +20 and −40, so the squared errors are 100, 400 and 1600. The mean squared error is (100 + 400 + 1600) / 3:
Look at how much the single $40k miss dominates: its squared error of 1600 is larger than the other two combined. A mean squared error of 700 is hard to read directly because it is in squared thousands of dollars, which is exactly why people report the RMSE of about 26.5 instead. The mean absolute error of 23.3 treats that big miss much more gently.
Why square the errors?
There are two everyday reasons and one mathematical reason to square the residuals. First, squaring removes the sign, so an error of +5 and an error of −5 both count as real mistakes instead of cancelling to zero. Second, squaring makes the MSE punish large errors disproportionately, which is usually what you want — being off by 100 is often much worse than being off by 10 twice.
The gradient of the MSE
Optimisers learn by following gradients, and the MSE has an especially friendly one: it is smooth everywhere and proportional to the error itself. A large error produces a large gradient and therefore a large corrective step, while a small error produces a gentle nudge. This clean, continuous gradient is a big reason gradient descent converges quickly on the MSE, and it is one advantage the metric holds over the mean absolute error, whose gradient has a constant magnitude and a kink at zero.
Mean squared error vs MAE vs RMSE
| Loss | Formula core | Units | Reaction to outliers |
|---|---|---|---|
| MSE | average of error² | target² | very sensitive |
| MAE | average of |error| | target | robust |
| RMSE | √MSE | target | very sensitive |
The practical difference is all about outliers. Because it squares residuals, the MSE (and its square root, RMSE) will chase a few extreme points hard, dragging the model toward them. The mean absolute error shrugs those points off. If your data has genuine, meaningful outliers you must not miss, the MSE is a feature; if it has noisy junk outliers you want to ignore, it is a bug, and MAE or Huber loss is the better choice.
When to use the MSE
Reach for the MSE when your target is continuous, your errors are roughly symmetric, and large mistakes really are proportionally worse than small ones — forecasting demand, predicting prices, or any physical measurement where a big deviation is genuinely costly. It is also the right default whenever you simply want a smooth, well-behaved objective for gradient descent and have no specific reason to prefer something more robust.
Common mistakes to avoid
Another subtle mistake is forgetting to scale your features. The mean squared error itself does not require scaling, but the optimisation that minimises it converges far faster when inputs are standardised, so a slow-training model is often a scaling problem rather than a loss problem.
Mean squared error in Python
import numpy as np
from sklearn.metrics import mean_squared_error
y_true = np.array([200, 250, 300])
y_pred = np.array([210, 230, 340])
mse = mean_squared_error(y_true, y_pred)
print("MSE :", mse) # 700.0
print("RMSE:", np.sqrt(mse)) # 26.46
# by hand
print(np.mean((y_true - y_pred) ** 2)) # 700.0In deep learning frameworks it is built in: torch.nn.MSELoss() in PyTorch and loss="mse" in Keras. Both compute exactly the MSE described above and hand its clean gradient back to the optimiser automatically. For the mathematical background, see the Wikipedia mean squared error article.
Putting it into practice
In a real project the MSE is usually your training loss and your validation metric at the same time, but it pays to watch more than one number. A common workflow is to train against the MSE for its smooth gradient, then report the RMSE so stakeholders can read the result in the original units, and also glance at the MAE to see whether a handful of outliers are inflating the score. If the MSE is high but the MAE is low, you almost certainly have a few large misses rather than a generally poor fit, and that diagnosis points you straight at the rows worth investigating. Tracking the metric on a held-out set epoch by epoch also tells you when the model stops improving, which is the signal to stop training before it overfits.