A tree split on a numeric feature x needs a value for every row. Real data has gaps, so the C4.5 approach scores the split on the rows that have a value, then scales the gain by the fraction of rows that are known. Rows with a missing value are sent down both branches later, weighted by how the known rows fell.
Implement fractional_split_gain(x, y, threshold), where x is a 1-D float array that may contain NaN, and y holds integer class labels.
known be the rows where x is not NaN, and let F = |known| / n.x <= threshold. Right branch: the other known rows.gain = F * (H(parent) - weighted child entropy), where H uses base-2 logs and the parent and children are computed on known rows only.(gain, p_left), where p_left is the fraction of known rows that went left.x and y must be 1-D with the same length. Otherwise raise ValueError.x is NaN, raise ValueError.0.Compute p_left and the gain from the same boolean mask, then reuse the entropy helper for both children.
No results yet
Run your code to check it against the examples, or submit to run every test.