numFeatures() - 1); $values = $dataset->feature($column); $type = $dataset->featureType($column); if ($type->isContinuous()) { $min = min($values); $max = max($values); $phi = getrandmax() / max(abs($max), abs($min)); $min = (int) floor($min * $phi); $max = (int) ceil($max * $phi); $value = rand($min, $max) / $phi; } else { $offset = array_rand(array_unique($values)); $value = $values[$offset]; } $subsets = $dataset->splitByFeature($column, $value); return new self($column, $value, $subsets); } /** * @param int $column * @param string|int|float $value * @param array{Dataset,Dataset} $subsets * @throws \Rubix\ML\Exceptions\InvalidArgumentException */ public function __construct(int $column, $value, array $subsets) { $this->column = $column; $this->value = $value; $this->subsets = $subsets; } /** * Return the feature column (index) of the split value. * * @return int */ public function column() : int { return $this->column; } /** * Return the split value. * * @return int|float|string */ public function value() { return $this->value; } /** * Return the left and right subsets of the training data. * * @throws RuntimeException * @return array{Dataset,Dataset} */ public function subsets() : array { if (!isset($this->subsets)) { throw new RuntimeException('Subsets property does not exist.'); } return $this->subsets; } /** * Remove any variables carried over from the parent node. */ public function cleanup() : void { unset($this->subsets); } }