Skip to content
DeepForgeby svx
All problems
MediumInformation Theoryinfo-342

Gini Gain of a Split

Problem

Compute the Gini gain of a split defined by groups, where each group is a list of indices into labels. The gain is the parent Gini impurity minus the size-weighted average of the child impurities. Return 0.0 when groups is empty or labels is empty.

Hint

Same weighting idea as information gain, but with the Gini impurity instead of entropy.

Test cases

case 1
in: [["a","a","b","b"],[[0,1],[2,3]]]
expected: 0.5
case 2
in: [["a","a","b","b","c"],[[0,1,2],[3,4]]]
expected: 0.17333333333333328
case 3
in: [["a","b"],[]]
expected: 0
case 4
in: [["a","a","a"],[[0,1,2]]]
expected: 0
case 5
in: [["a","b","c","c"],[[0,1],[2,3]]]
expected: 0.375
Starter codePython
def gini_gain(labels, groups):
    # Your code here
    pass

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