Skip to content
DeepForgeby svx
All problems
HardML Fundamentalsml-289

Qini Coefficient

Problem

Compute the Qini coefficient for an uplift model. Sort samples by predicted uplift descending (ties by index) and track value_k = cum_treated_positives/n_treated - cum_control_positives/n_control. The coefficient is the trapezoidal area under this curve minus the random diagonal, divided by n.

Return 0.0 when the input is empty or a treatment group is missing.

Hint

A good uplift model concentrates treated responders at the top of the ranking.

Test cases

case 1
in: [[1,1,0,0],[1,0,1,0],[0.9,0.8,0.2,0.1]]
expected: 0.25
case 2
in: [[1,1,0,0],[1,0,1,0],[0.1,0.2,0.8,0.9]]
expected: -0.25
case 3
in: [[1,0],[1,0],[0.5,0.5]]
expected: 0.25
case 4
in: [[],[],[]]
expected: 0
Starter codePython
def qini_coefficient(treatment, outcome, uplift_scores):
    # Your code here
    pass

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