Skip to content
DeepForgeby svx
All problems
EasyML Fundamentalsml-017

Mean Squared Error

Problem

Compute the mean squared error: MSE = (1/n) * sum((y_true_i - y_pred_i)^2).

Empty input returns 0.0.

Hint

Average the squared residuals.

Test cases

case 1
in: [[1,2,3,4],[1,2,3,4]]
expected: 0
case 2
in: [[1,2,3],[1,2,5]]
expected: 1.3333333333333333
case 3
in: [[0,0],[3,4]]
expected: 12.5
case 4
in: [[],[]]
expected: 0
Starter codePython
def mean_squared_error(y_true, y_pred):
    # Your code here
    pass

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