Back to Practice
#0139
Majority Class Baseline Accuracy
EasyML15 min10 XP
Problem
Given labels, return the accuracy of a classifier that always predicts the most frequent label. Break ties by choosing any tied class.
Why This Matters
A model must beat simple baselines. Accuracy without a baseline is hard to judge.
Function Signature
def majority_baseline_accuracy(labels):
Examples
Example 1
Input[1, 1, 0, 1, 0]
Output0.6
Class 1 appears 3 of 5 times.
Constraints
- Return the exact requested structure.
- Handle normal edge cases cleanly.
- Prefer readable code over clever shortcuts.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Input[1, 1, 0, 1, 0]
Expected0.6
Class 1 appears 3 of 5 times.
Hidden Test Categories
all same classtiestring labels