Skip to content
C

Problem 3: Compare Precision and Recall on an Imbalanced Dataset

Easypython

Problem Description

Write a Python program that demonstrates how a model predicting only the majority class on an imbalanced dataset achieves high accuracy but poor Recall for the minority class.

Input

An imbalanced set of actual labels (e.g., mostly 0s, few 1s), and a set of predictions that are all 0.

Output

The Accuracy, Precision, and Recall for this "always predict majority" scenario.

Constraints

  • At least 90% of actual labels should be the majority class.

Example Input

text
actual=[0,0,0,0,0,0,0,0,0,1], predicted=[0,0,0,0,0,0,0,0,0,0]

Example Output

text
Accuracy: 0.9 Precision: 0.0 (undefined/zero division handled) Recall: 0.0

Concepts Covered

Imbalanced data, metric limitations, zero_division parameter handling.

Input (stdin)

Output

Run your code to see output here...