Information Gain of a Split

~12 mincode completion

Implement information_gain(y, left) returning the gain in bits, where left is a 0/1 array marking the rows that go left.

Where this shows up

~12 min

8 employers weight this skill

2 health and bio companies, 2 quant funds, 2 enterprise vendors, 1 AI product company, 1 frontier lab. Top match scores 87.

Python
import numpy as np


def information_gain(y, left):
    """
    Entropy reduction (base 2) from splitting labels y.

    Args:
        y:    array of shape (n,), class labels (any number of classes)
        left: array of shape (n,), 1 if the row goes left, 0 if right

    Returns:
        float: H(parent) - (n_L/n) H(left) - (n_R/n) H(right)
    """
    # YOUR CODE HERE
    pass

Run your code to see results

⌘↵ runs against the visible tests

Loading docs…

The AI Mentor needs an account

It reads your code and the failing tests and nudges you toward the fix without handing you the answer. Free accounts get it on every problem you're working on today.