Skip to content
DeepForgeby svx
All problems
EasyML Fundamentalsml-018

Mean Absolute Error for Regression

Problem

Compute the mean absolute error: MAE = (1/n) * sum(|y_true_i - y_pred_i|).

Empty input returns 0.0.

Hint

Average the absolute residuals.

Test cases

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

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