Compute the information gain produced by a boolean split of classification labels.
H(Y)=−c=1∑Cpclog2pc IG=H(Y)−NNLH(YL)−NNRH(YR)Here, pc is the proportion of class c, YL contains labels where split_mask is true, YR contains the remaining labels, and N=NL+NR. A split with an empty side has gain zero. Return the gain as a Python float.
Input: y = [0, 0, 1, 1], split_mask = [true, true, false, false]
Output: 1.0
Explanation: Each child is pure, so the split removes all one bit of parent entropy.
Input: y = [0, 0, 0, 1], split_mask = [true, false, false, true]
Output: 0.311278
Input: y = [0, 0, 1, 2], split_mask = [true, false, true, false]
Output: 0.5
Use np.unique(labels, return_counts=True) inside a small entropy helper.
Form children with labels[mask] and labels[~mask].
Sign in to take notes on this problem
Accepts: array
Accepts: array
Compute the information gain produced by a boolean split of classification labels.
H(Y)=−c=1∑Cpclog2pc IG=H(Y)−NNLH(YL)−NNRH(YR)Here, pc is the proportion of class c, YL contains labels where split_mask is true, YR contains the remaining labels, and N=NL+NR. A split with an empty side has gain zero. Return the gain as a Python float.
Input: y = [0, 0, 1, 1], split_mask = [true, true, false, false]
Output: 1.0
Explanation: Each child is pure, so the split removes all one bit of parent entropy.
Input: y = [0, 0, 0, 1], split_mask = [true, false, false, true]
Output: 0.311278
Input: y = [0, 0, 1, 2], split_mask = [true, false, true, false]
Output: 0.5
Use np.unique(labels, return_counts=True) inside a small entropy helper.
Form children with labels[mask] and labels[~mask].
Sign in to take notes on this problem
Accepts: array
Accepts: array