Skip to content
DeepForgeby svx
All problems
MediumML Fundamentalsml-140

Feature Importance from Split Gains

Problem

Aggregate split gains into feature importances. Sum the gain of all splits per feature, then normalize by the total gain.

Return a dict mapping str(feature) to its share; if the total gain is 0, all shares are 0.0. Empty input returns {}.

Hint

Sum gains per feature, then divide by the total gain across all splits.

Test cases

case 1
in: [[[0,2],[1,1],[0,1]]]
expected: {"0":0.75,"1":0.25}
case 2
in: [[[0,0.5],[1,0.5]]]
expected: {"0":0.5,"1":0.5}
case 3
in: [[[0,0]]]
expected: {"0":0}
case 4
in: [[]]
expected: {}
Starter codePython
def feature_importance(splits):
    # Your code here
    pass

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