protected function terminate(Labeled $dataset) : BinaryNode
    {
        $n = $dataset->numRows();

        $labels = $dataset->labels();

        $counts = array_count_values($labels);

        $outcome = argmax($counts);

        $probabilities = [];

        foreach ($counts as $class => $count) {
            $probabilities[$class] = $count / $n;
        }

        $impurity = 1. - (max($counts) / $n) ** 2;

        return new Outcome($outcome, $probabilities, $impurity, $n);
    }