Accuracy Practice Problem
This data science coding problem helps you practice Evaluation Metrics, accuracy, and implementation skills. Read the problem statement, write your solution, and strengthen your understanding of Evaluation Metrics.
- Problem ID: 21
- Problem key: 21-accuracy
- URL: https://datacrack.app/solve/21-accuracy
- Difficulty: easy
- Topic: Evaluation Metrics
- Module: Introduction to Machine Learning
Problem Statement
## 🧩 Accuracy Score
### 🎯 Goal
Compute the **accuracy** of a binary classification model.
---
### 📥 Input / 📤 Output
**Input**
- `y_true` (`list[int]`): true labels (0 or 1)
- `y_pred` (`list[int]`): predicted labels (0 or 1)
**Assumption:**:
- `y_true` and `y_pred` have the **same non-zero length**.
**Output**
- `float`: accuracy score
---
### 💻 Task Description
Accuracy is the fraction of correct predictions:
$$
\text{Accuracy} = \frac{\#\text{correct predictions}}{n}
$$
Return the accuracy as a float.
---
### 🧩 Starter Code
```python
def accuracy_score(y_true, y_pred):
pass
```
⸻
💡 Example
```python
y_true = [1, 0, 1, 1, 0]
y_pred = [1, 1, 1, 0, 0]
accuracy_score(y_true, y_pred)
```
**Expected Output**
```
0.6
```
⸻
Starter Code
def accuracy_score(y_true, y_pred):
pass