Course contentsShow
← Computer Science
Lesson 2818 of 2,87263. Classical ML AlgorithmsFree lesson

Loss Functions: Mean Squared Error

Defining MSE as the objective function that measures prediction error and guides model training.

Loss Functions: Mean Squared Error

What you'll learn: How Mean Squared Error (MSE) quantifies prediction mistakes and serves as the objective function that linear regression tries to minimize.

What is Mean Squared Error?

You've seen the linear model equation that generates predictions. But how do we measure how good those predictions are? That's where Mean Squared Error (MSE) comes in.

MSE calculates the average of all squared differences between your model's predictions and the actual target values. For each data point, you:

  1. Compute the prediction error (predicted value minus actual value)
  2. Square that error (making all errors positive and penalizing larger errors more heavily)
  3. Average all the squared errors across your dataset

Why Square the Errors?

Think of MSE like a golf scorecard for your model. Just being "close on average" isn't good enough—a prediction that's +10 off and another that's -10 off shouldn't cancel out to "perfect." Squaring ensures all errors count, and it heavily penalizes large mistakes. A prediction off by 10 contributes 100 to MSE, while one off by 2 contributes only 4.

The squaring also gives MSE a nice mathematical property: it's smooth and differentiable everywhere, which makes it easy to optimize using calculus-based methods.

MSE as the Training Objective

During training, linear regression searches for the model parameters (weights and bias) that produce the lowest possible MSE on your training data. This is what "fitting" the model means—finding the line that minimizes the average squared distance from your data points.

Key Takeaway: Mean Squared Error (MSE) measures prediction quality by averaging squared errors, serving as the loss function that guides linear regression to find optimal model parameters through minimization.