Skip to content
DeepForgeby svx
All problems
EasyML Fundamentalsml-125

Class Imbalance Ratio

Problem

Compute the class imbalance ratio: count of the majority class divided by count of the minority class.

A single class gives 1.0; empty input returns 0.0.

Hint

Ratio of the largest class count to the smallest.

Test cases

case 1
in: [["a","a","a","b"]]
expected: 3
case 2
in: [[1,1,2,2]]
expected: 1
case 3
in: [[5]]
expected: 1
case 4
in: [[]]
expected: 0
Starter codePython
def imbalance_ratio(labels):
    # Your code here
    pass

4 test cases · run your code against them in the editor