The team needs a reliable implementation for decision-tree training in a production-oriented ML workflow. A small implementation error can change the model input or metric enough to make a downstream result misleading.
Compute the Gini impurity of a binary label vector for a decision-tree node.
Compute 1−p2−(1−p)2 where p is the fraction of labels equal to 1. Labels must be 0 or 1; an empty node has impurity 0.0.
Implement solve(y).
Returns. Return a float between 0 and 0.5.
Example 1
Input:
solve([0, 0, 1, 1])
Output:
0.5
Example 2
Input:
solve([1, 1, 1, 1])
Output:
0.0
Example 3
Input:
solve([0, 1, 1, 1])
Output:
0.375
No results yet
Run your code to check it against the examples, or submit to run every test.