Evaluation Summary for Classifiers Practice Problem
This data science coding problem helps you practice Evaluation Metrics for Classification, evaluation summary for classifiers, and implementation skills. Read the problem statement, write your solution, and strengthen your understanding of Evaluation Metrics for Classification.
- Problem ID: 146
- Problem key: 146-evaluation-summary-for-classifiers
- URL: https://datacrack.app/solve/146-evaluation-summary-for-classifiers
- Difficulty: easy
- Topic: Evaluation Metrics for Classification
- Module: Introduction to Machine Learning
Problem Statement
## 🧩 Evaluation Summary for Classifiers
### 🎯 Goal
Create a comprehensive evaluation function that returns all key binary classification metrics in one dictionary.
---
### 💻 Task Description
In real-world projects, looking at a single metric like accuracy is often not enough. You need to see the full picture to understand how your model is truly performing.
Implement a function that computes the following four metrics:
1. **Accuracy**
2. **Precision**
3. **Recall**
4. **F1 Score**
You may use `sklearn.metrics` to compute these metrics.
For Precision, Recall, and F1, use `zero_division=0`.
Return each metric rounded to 6 decimal places.
---
### 📥 Input / 📤 Output
**Input**
- `y_true` (`list[int]`): true labels (0 or 1)
- `y_pred` (`list[int]`): predicted labels (0 or 1)
**Output**
- `dict`: A dictionary containing `"accuracy"`, `"precision"`, `"recall"`, and `"f1"`.
- Each metric should be rounded to 6 decimal places.
---
### 🧩 Starter Code
```python
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score
def evaluate_classifier(y_true, y_pred):
"""
Returns a dictionary of classification metrics.
"""
pass
```
---
### 💡 Example
```python
y_true = [1, 0, 1, 1, 0]
y_pred = [1, 1, 1, 0, 0]
evaluate_classifier(y_true, y_pred)
```
**Expected Output**
```json
{
"accuracy": 0.6,
"precision": 0.666667,
"recall": 0.666667,
"f1": 0.666667
}
```
---
Starter Code
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score
def evaluate_classifier(y_true, y_pred):
"""
Returns a dictionary of classification metrics.
"""
pass