Perform a partial train.

@param \Rubix\ML\Datasets\Dataset $dataset
979828
public function partial(Dataset $dataset) : void
    {
        if ($this->elastic) {
            $this->update($dataset);
        }

        if ($this->estimator instanceof Online) {
            $this->estimator->partial($dataset);
        }
    }
1078749
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);
    }
1334506
public function train(Dataset $dataset) : void
    {
        if (!$dataset instanceof Labeled) {
            throw new InvalidArgumentException('This estimator requires a'
                . ' labeled training set.');
        }

        DatasetIsCompatibleWithEstimator::check($dataset, $this);

        $k = $dataset->numColumns();

        $this->columns = range(0, $dataset->numColumns() - 1);
        $this->maxFeatures = $this->maxFeatures ?? (int) round(sqrt($k));

        $this->grow($dataset);

        $this->columns = [];
    }
417909
protected function update(Dataset $dataset) : void
    {
        foreach ($this->transformers as $transformer) {
            if ($transformer instanceof Elastic) {
                $transformer->update($dataset);

                if ($this->logger) {
                    $this->logger->info('Updated '
                        . Params::shortName($transformer));
                }
            }

            $dataset->apply($transformer);

            if ($this->logger) {
                $this->logger->info('Applied '
                    . Params::shortName($transformer));
            }
        }
    }
119505
public function execute(DataSetInterface $dataSet)
    {
        $quoteEntity = SpyQuoteQuery::create()
            ->filterByKey($dataSet[CartDataSetInterface::KEY_CART])
            ->findOneOrCreate();

        $quoteEntity->fromArray($dataSet->getArrayCopy());
        $quoteEntity
            ->setFkStore($dataSet[CartDataSetInterface::ID_STORE]);

        $quoteEntity->save();
    }
163943
public function grow(Labeled $dataset) : void
    {
        $this->featureCount = $dataset->numColumns();

        $depth = 1;

        $this->root = $this->split($dataset);

        $stack = [[$this->root, $depth]];

        while ($stack) {
            [$current, $depth] = array_pop($stack) ?? [];

            [$left, $right] = $current->groups();

            $current->cleanup();

            $depth++;

            if ($left->empty() or $right->empty()) {
                $node = $this->terminate($left->append($right));
    
                $current->attachLeft($node);
                $current->attachRight($node);

                continue 1;
            }
    
            if ($depth >= $this->maxDepth) {
                $current->attachLeft($this->terminate($left));
                $current->attachRight($this->terminate($right));
                
                continue 1;
            }

            if ($left->numRows() > $this->maxLeafSize) {
                $node = $this->split($left);

                if ($node->purityIncrease() + self::BETA > $this->minPurityIncrease) {
                    $current->attachLeft($node);

                    $stack[] = [$node, $depth];
                } else {
                    $current->attachLeft($this->terminate($left));
                }
            } else {
                $current->attachLeft($this->terminate($left));
            }
    
            if ($right->numRows() > $this->maxLeafSize) {
                $node = $this->split($right);
    
                if ($node->purityIncrease() + self::BETA > $this->minPurityIncrease) {
                    $current->attachRight($node);

                    $stack[] = [$node, $depth];
                } else {
                    $current->attachRight($this->terminate($right));
                }
            } else {
                $current->attachRight($this->terminate($right));
            }
        }
    }
674420
public function predict(Dataset $dataset) : array
    {
        if (!$this->model) {
            throw new RuntimeException('Estimator has not been trained.');
        }

        DatasetIsCompatibleWithEstimator::check($dataset, $this);

        return array_map([$this->model, 'predict'], $dataset->samples());
    }
366670
public function fit(Dataset $dataset) : void
    {
        $columns = $dataset->columnsByType(DataType::CATEGORICAL);

        $this->categories = [];

        foreach ($columns as $column => $values) {
            $categories = array_values(array_unique($values));

            $this->categories[$column] = array_flip($categories);
        }
    }
1248273
private function buildMax(Dataset $dataset): self
    {
        $this->max = new Quartile(max(...$dataset->ordinates()));

        return $this;
    }
698003
public function fit(Dataset $dataset) : void
    {
        $this->intervals = [];

        $columns = $dataset->columnsByType(DataType::CONTINUOUS);

        foreach ($columns as $column => $values) {
            $min = min($values);
            $max = max($values);

            $edges = Vector::linspace($min, $max, $this->bins + 1)->asArray();

            array_shift($edges);

            $this->intervals[$column] = $edges;
        }
    }
133561
public function train(Dataset $dataset) : void
    {
        DatasetIsCompatibleWithEstimator::check($dataset, $this);

        if ($this->logger) {
            $this->logger->info('Learner init ' . Params::stringify([
                'c' => $this->c,
                'fuzz' => $this->fuzz,
                'kernel' => $this->kernel,
                'epochs' => $this->epochs,
                'min_change' => $this->minChange,
                'seeder' => $this->seeder,
            ]));
        }

        $this->centroids = $this->seeder->seed($dataset, $this->c);

        $this->steps = $memberships = [];

        $samples = $dataset->samples();
        $rotated = $dataset->columns();

        $previous = INF;

        for ($epoch = 1; $epoch <= $this->epochs; $epoch++) {
            $memberships = array_map([self::class, 'membership'], $samples);

            foreach ($this->centroids as $cluster => &$centroid) {
                foreach ($rotated as $column => $values) {
                    $sigma = $total = 0.;

                    foreach ($memberships as $i => $probabilities) {
                        $weight = $probabilities[$cluster] ** $this->fuzz;

                        $sigma += $weight * $values[$i];
                        $total += $weight;
                    }

                    $centroid[$column] = $sigma / ($total ?: EPSILON);
                }
            }

            $inertia = $this->inertia($dataset, $memberships);

            $this->steps[] = $inertia;

            if ($this->logger) {
                $this->logger->info("Epoch $epoch complete, inertia=$inertia");
            }

            if (is_nan($inertia)) {
                break 1;
            }

            if (abs($previous - $inertia) < $this->minChange) {
                break 1;
            }

            $previous = $inertia;
        }

        if ($this->logger) {
            $this->logger->info('Training complete');
        }
    }
859036
public function execute(DataSetInterface $dataSet): void
    {
        $productAlternativeQuery = SpyProductAlternativeQuery::create()
            ->filterByFkProduct($dataSet[ProductAlternativeDataSetInterface::FK_PRODUCT]);

        if ($dataSet[ProductAlternativeDataSetInterface::KEY_COLUMN_ALTERNATIVE_PRODUCT_CONCRETE_SKU]) {
            $this->saveConcreteAlternative($dataSet, $productAlternativeQuery);
        }

        if ($dataSet[ProductAlternativeDataSetInterface::KEY_COLUMN_ALTERNATIVE_PRODUCT_ABSTRACT_SKU]) {
            $this->saveAbstractAlternative($dataSet, $productAlternativeQuery);
        }
    }
1344603
public static function split(Labeled $dataset) : self
    {
        $columns = $dataset->columns();

        $variances = array_map([Stats::class, 'variance'], $columns);

        $column = argmax($variances);

        $value = Stats::median($columns[$column]);

        $groups = $dataset->partition($column, $value);

        $min = $max = [];

        foreach ($columns as $values) {
            $min[] = min($values);
            $max[] = max($values);
        }

        return new self($column, $value, $groups, $min, $max);
    }
959146
public function train(Dataset $dataset) : void
    {
        DatasetIsCompatibleWithEstimator::check($dataset, $this);

        $this->centroids = $this->seeder->seed($dataset, $this->k);

        $sizes = array_fill(1, $this->k, 0);
        $sizes[0] = $dataset->numRows();

        $this->sizes = $sizes;

        $this->steps = [];

        $this->partial($dataset);
    }
14701
public function fit(Dataset $dataset) : void
    {
        $this->maxabs = [];

        foreach ($dataset->types() as $column => $type) {
            if ($type === DataType::CONTINUOUS) {
                $this->maxabs[$column] = -INF;
            }
        }

        $this->update($dataset);
    }
977529
public function prepend(Dataset $dataset) : self
    {
        if (!$dataset instanceof Labeled) {
            throw new InvalidArgumentException('Can only merge with a labeled'
                . 'dataset.');
        }

        $samples = array_merge($dataset->samples(), $this->samples);
        $labels = array_merge($dataset->labels(), $this->labels);

        return self::quick($samples, $labels);
    }
1080487
public function fit(Dataset $dataset) : void
    {
        $this->minimums = $this->maximums = $this->scales = $this->mins = [];

        foreach ($dataset->types() as $column => $type) {
            if ($type === DataType::CONTINUOUS) {
                $this->minimums[$column] = INF;
                $this->maximums[$column] = -INF;
            }
        }

        $this->update($dataset);
    }