Label imbalance ratio

Write codeEasy10 minMeta and Google style

Your task

Before trusting an accuracy number, your team checks how skewed the eval set is: a model that always answers 'not spam' looks great on a 99-to-1 dataset. Given a list of binary labels (0s and 1s), count each class and return floor(majority_count / minority_count) as an integer imbalance ratio. If the list is empty or only one class is present, return -1. Example: [0, 0, 0, 0, 1] has 4 zeros and 1 one, so return 4.

Examples

imbalance_ratio(labels: list[int]) -> int
Example 1
Inputimbalance_ratio([0, 0, 0, 0, 1])
Output4