Back to Practice
#0187
Mean Absolute Error
EasyML15 min10 XP
Problem
Given y_true and y_pred, return the mean absolute error.
Why This Matters
MAE is a plain-English regression metric: on average, how far are predictions from the true value?
Function Signature
def mean_absolute_error(y_true, y_pred):
Examples
Example 1
Inputy_true = [3, -1, 2], y_pred = [2, 1, 2]
Output1.0
Absolute errors are 1, 2, 0, and their average is 1.
Constraints
- Return the exact requested result.
- Handle common edge cases.
- Keep the solution readable before optimizing.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Inputy_true = [3, -1, 2], y_pred = [2, 1, 2]
Expected1.0
Absolute errors are 1, 2, 0, and their average is 1.
Hidden Test Categories
minimal inputrepeated valueslarger realistic input