protected function splitImpurity(array $groups) : float
    {
        $n = array_sum(array_map('count', $groups));

        $impurity = 0.;

        foreach ($groups as $dataset) {
            $k = $dataset->numRows();

            if ($k < 2) {
                continue 1;
            }

            $variance = Stats::variance($dataset->labels());

            $impurity += ($k / $n) * $variance;
        }

        return $impurity;
    }
protected function splitImpurity(array $groups) : float
    {
        $n = array_sum(array_map('count', $groups));

        $impurity = 0.;

        foreach ($groups as $dataset) {
            $k = $dataset->numRows();

            if ($k < 2) {
                continue 1;
            }

            $variance = Stats::variance($dataset->labels());

            $impurity += ($k / $n) * $variance;
        }

        return $impurity;
    }
protected function splitImpurity ( array $ groups ) : float { $ n = array_sum ( array_map ( 'count' , $ groups ) ) ; $ impurity = 0. ; foreach ( $ groups as $ dataset ) { $ k = $ dataset -> numRows ( ) ; if ( $ k < 2 ) { continue 1 ; } $ variance = Stats :: variance ( $ dataset -> labels ( ) ) ; $ impurity += ( $ k / $ n ) * $ variance ; } return $ impurity ; }
Calculate the weighted variance for the split.

@param array $groups
@return float
Calculate the weighted variance for the split .