WRITE · TRACE · UNDERSTAND
Decision Stumps
Try thresholds and choose the lowest weighted Gini impurity
Your experiment
best_split(values, labels) returns the midpoint between consecutive distinct sorted values with the lowest weighted Gini impurity. Equal scores choose the smaller threshold. Return None when fewer than two distinct values exist.
Python runs in your browser. Your draft stays on this device.
What to look for
A split is useful when it leaves purer groups. Weight each group by its size, then compare candidate midpoints. Scanning thresholds in ascending order and accepting only a lower score gives a deterministic smallest-threshold tie break.
Watch your code work
Ready to experimentWrite a solution or load the worked answer, then choose Trace & check.
Step through arrays, variables and training curves produced by your own Python.