Linear Regression
Beginner
Compute Mean Squared Error
Beginner
~8 min
code completion
Mean Squared Error Loss
Before we can optimize a model, we need to measure how wrong it is. Mean Squared Error (MSE) is the most common loss function for regression:
where are the true labels and are the predictions.
Properties of MSE:
Your task: Implement mean_squared_error(y_true, y_pred) using NumPy. Do not use a for loop.
Example Tests
Perfect predictions → MSE = 0
Input: {"y_pred":[1,2,3],"y_true":[1,2,3]}
Expected: 0
Known MSE value
Input: {"y_pred":[2,2,2,2],"y_true":[1,2,3,4]}
Expected: 1.5
Single element
Input: {"y_pred":[3],"y_true":[5]}
Expected: 4