LearnPy Hub
← Exploratory Data Analysis (EDA) problems
Easy

Is the Target Balanced?

The column label is what a model would predict. Print each label with its share of the rows as a percentage with 1 decimal, most common first (ties alphabetically). Then print imbalanced if the most common label covers more than 80% of the rows, otherwise ok.

Input

A CSV table: a header line, then one line per row (an empty field means a missing value), then a line END.

Output

One line per label (label 62.5%), then ok or imbalanced.

Sample 1

Input
label
pass
pass
fail
pass
fail
pass
pass
pass
END
Output
pass 75.0%
fail 25.0%
ok

Sample 2

Input
x,label
1,spam
2,ham
3,ham
4,ham
5,ham
6,ham
7,ham
8,ham
9,ham
10,ham
END
Output
ham 90.0%
spam 10.0%
imbalanced
solution.py
Output appears here
Hints
Is the Target Balanced? · Python practice problem · LearnPy Hub