🧭 Do not search for the first 15 minutes. When stuck: re-read the requirements → define I/O → choose the data structure → trace a small example by hand → write code.
Implement best_split(X, y), which finds the split at one decision-tree node that
minimizes the weighted Gini impurity.
X # (n, d) two-dimensional array — real-valued features
y # (n,) labels, 0 or 1
It may arrive as a list of lists or as a numpy array.
For each feature, sort its values ascending, drop duplicates, and take the midpoint of every adjacent pair as a candidate.
feature values [1, 2, 2, 4] → unique [1, 2, 4] → candidate thresholds [1.5, 3.0]
X[:, f] <= t go left; the rest go right.(feature_index, threshold)
None.Implement best_split(X, y).
(feature index, threshold) tuple; the threshold is a float.None when no valid split exists.