Decision stump Gini split
Your task
Find the best split for a decision stump on a single numeric feature using Gini impurity. Given X (a list of numeric feature values) and y (binary labels 0/1) of equal length, consider every threshold equal to a value present in X. A sample goes left when X[i] <= threshold, else right. The weighted Gini of a split is (n_left/n)*gini(left) + (n_right/n)*gini(right), where gini of a group = 1 - sum_over_classes (fraction)^2; an empty group has gini 0. Return [best_threshold, best_weighted_gini], with the gini rounded to 6 decimals, choosing the threshold that minimizes weighted Gini; break ties by the smallest threshold. There is at least one sample.
Examples
best_split(X: list[float], y: list[int]) -> list[float]Example 1
Input
best_split([1, 2, 3, 4], [0, 0, 1, 1])Output
[2, 0]