Loading...
Find the best threshold for splitting a feature to maximize information gain.
Given a list of feature values and corresponding labels, try every midpoint between consecutive sorted unique feature values as a potential split threshold. For each threshold, split the data into left (≤ threshold) and right (> threshold) subsets.
Return the threshold that gives the highest information gain, along with the gain value, as a tuple (threshold, gain). Both rounded to 4 decimal places.
If there's no possible split (all values identical), return (None, 0.0).
feature_values = [1, 2, 3, 4] labels = [0, 0, 1, 1]
(2.5, 1.0)