Skip to content
DeepForgeby svx
All problems
EasyML Fundamentalsproj-012

Mean Squared Error Loss

Problem

Compute mean squared error between predictions and targets.

L = (1/n) * sum((y_pred_i - y_true_i)^2). Return 0.0 for empty inputs.

Hint

Square the residuals, average, and the loss stays non-negative.

Test cases

case 1
in: [[1,2],[1,2]]
expected: 0
case 2
in: [[1,3],[2,1]]
expected: 2.5
case 3
in: [[0],[0]]
expected: 0
case 4
in: [[1,2,3],[3,2,1]]
expected: 2.6666666666666665
Starter codePython
def mse_loss(y_pred, y_true):
    # Your code here
    pass

4 test cases · run your code against them in the editor