MAE Practice Problem
This data science coding problem helps you practice Evaluation Metrics for Regression, mae, and implementation skills. Read the problem statement, write your solution, and strengthen your understanding of Evaluation Metrics for Regression.
- Problem ID: 139
- Problem key: 139-mae
- URL: https://datacrack.app/solve/139-mae
- Difficulty: easy
- Topic: Evaluation Metrics for Regression
- Module: Introduction to Machine Learning
Problem Statement
## 🧩 Mean Absolute Error (MAE)
### 🎯 Goal
Compute the **Mean Absolute Error** between true and predicted values.
---
### 💻 Task Description
1. Compute the absolute difference between each true and predicted value
2. Return the **mean** of those absolute differences
3. Return the result rounded to 6 decimal places.
$$\text{MAE} = \frac{1}{N}\sum_{i=1}^{N}|y_{\text{true},i} - y_{\text{pred},i}|$$
---
### 📥 Input / 📤 Output
**Input**
- `y_true` (`list[float]`): true target values
- `y_pred` (`list[float]`): predicted values
**Output**
- `float`: the MAE score rounded to 6 decimal places
---
### 🧩 Starter Code
```python
import numpy as np
def mean_absolute_error(y_true, y_pred):
"""
Returns the Mean Absolute Error.
"""
pass
```
---
### 💡 Example
```python
y_true = [3, -0.5, 2, 7]
y_pred = [2.5, 0.0, 2, 8]
mean_absolute_error(y_true, y_pred)
```
**Expected Output**
```
0.5
```
---
Starter Code
import numpy as np
def mean_absolute_error(y_true, y_pred):
"""
Returns the Mean Absolute Error.
"""
pass