BasicsDispersionRobust StatsGoogleMetaJane Street
Problem
Implement mean_absolute_deviation(x) returning MAD=n1∑i=1n∣xi−xˉ∣ as a Python float.
Why It Matters: MAD measures average linear distance from the mean without squaring deviations, making it more intuitive and less outlier-sensitive than standard deviation.
Function Signature
import numpy as np
def mean_absolute_deviation(x) -> float:
Sample Input & Output
Example 1: Symmetric Deviations
Input:
x = [2.0, 4.0, 6.0, 8.0]
Expected Output:
2.0
Explanation: Mean is 5.0; absolute deviations are [3, 1, 1, 3], average is 8 / 4 = 2.0.
Example 2: Single Outlier
Input:
x = [1.0, 1.0, 1.0, 9.0]
Expected Output:
3.0
Explanation: Mean is 3.0; absolute deviations are [2, 2, 2, 6], average is 12 / 4 = 3.0.
Constraints & Edge Cases
- Return MAD as a Python float.
- Divide by
n(mean of absolute deviations). - Return
0.0for constant arrays.
Constraints & Evaluation Criteria
- Return MAD as a Python float.
Hints
Python 3⌘/Ctrl+Enter to Run · ⌘/Ctrl+Shift+Enter to Submit
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
[2, 4, 6, 8]
Expected Output / Criteria
2.0