BasicsRegression MetricsNumPyGoogleMetaAmazon
Problem
Implement mae_and_mse(y_true, y_pred) returning (mae, mse) for two equal-length 1D arrays.
Why It Matters: Choosing between MAE (robust to outliers) and MSE (heavily penalizes large errors) is one of the most common regression interview questions.
Sample Inputs & Expected Outputs
Example 1 — Mixed positive & negative errors
>>> mae_and_mse([3.0, 5.0, 2.0], [2.0, 5.0, 4.0])
(1.0, 1.6667)
Errors [1, 0, -2] -> MAE = (1+0+2)/3 = 1.0, MSE = (1+0+4)/3 = 1.6667.
Example 2 — Outlier sensitivity
>>> mae_and_mse([10, 20, 30, 40], [10, 20, 30, 50])
(2.5, 25.0)
One error of 10 makes MSE (25.0) 10x larger than MAE (2.5).
Example 3 — Perfect predictions
>>> mae_and_mse([1.0, 2.0], [1.0, 2.0])
(0.0, 0.0)
Zero error gives MAE=0 and MSE=0.
Constraints & Edge Cases
- Return
(mae, mse)as Python floats.
Constraints & Evaluation Criteria
- Return `(mae, mse)` as Python floats.
Hints
Python 3⌘/Ctrl+Enter to Run · ⌘/Ctrl+Shift+Enter to Submit
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
[3,5,2] vs [2,5,4]
Expected Output / Criteria
(1.0, 1.6667)