protected function split(Labeled $dataset) : Decision
    {
        $bestVariance = INF;
        $bestColumn = $bestValue = null;
        $bestGroups = [];

        shuffle($this->columns);

        foreach (array_slice($this->columns, 0, $this->maxFeatures) as $column) {
            $values = array_unique($dataset->column($column));

            foreach ($values as $value) {
                $groups = $dataset->partition($column, $value);

                $variance = $this->splitImpurity($groups);

                if ($variance < $bestVariance) {
                    $bestColumn = $column;
                    $bestValue = $value;
                    $bestGroups = $groups;
                    $bestVariance = $variance;
                }

                if ($variance <= $this->tolerance) {
                    break 2;
                }
            }
        }

        return new Decision($bestColumn, $bestValue, $bestGroups, $bestVariance);
    }
protected function split(Labeled $dataset) : Decision
    {
        $bestVariance = INF;
        $bestColumn = $bestValue = null;
        $bestGroups = [];

        shuffle($this->columns);

        foreach (array_slice($this->columns, 0, $this->maxFeatures) as $column) {
            $values = array_unique($dataset->column($column));

            foreach ($values as $value) {
                $groups = $dataset->partition($column, $value);

                $variance = $this->splitImpurity($groups);

                if ($variance < $bestVariance) {
                    $bestColumn = $column;
                    $bestValue = $value;
                    $bestGroups = $groups;
                    $bestVariance = $variance;
                }

                if ($variance <= $this->tolerance) {
                    break 2;
                }
            }
        }

        return new Decision($bestColumn, $bestValue, $bestGroups, $bestVariance);
    }
protected function split ( Labeled $ dataset ) : Decision { $ bestVariance = INF ; $ bestColumn = $ bestValue = null ; $ bestGroups = [ ] ; shuffle ( $ this -> columns ) ; foreach ( array_slice ( $ this -> columns , 0 , $ this -> maxFeatures ) as $ column ) { $ values = array_unique ( $ dataset -> column ( $ column ) ) ; foreach ( $ values as $ value ) { $ groups = $ dataset -> partition ( $ column , $ value ) ; $ variance = $ this -> splitImpurity ( $ groups ) ; if ( $ variance < $ bestVariance ) { $ bestColumn = $ column ; $ bestValue = $ value ; $ bestGroups = $ groups ; $ bestVariance = $ variance ; } if ( $ variance <= $ this -> tolerance ) { break 2 ; } } } return new Decision ( $ bestColumn , $ bestValue , $ bestGroups , $ bestVariance ) ; }
Greedy algorithm to chose the best split for a given dataset as
determined by the variance of the split.

@param \Rubix\ML\Datasets\Labeled $dataset
@return \Rubix\ML\Graph\Nodes\Decision
Greedy algorithm to chose the best split for a given dataset as determined by the variance of the split .