column = $column; $this->value = $value; $this->groups = $groups; $this->impurity = $impurity; $this->samplesCount = (int) array_sum(array_map(static function (array $group): int { return count($group[0]); }, $groups)); } public function column(): int { return $this->column; } /** * @return mixed */ public function value() { return $this->value; } public function groups(): array { return $this->groups; } public function impurity(): float { return $this->impurity; } public function samplesCount(): int { return $this->samplesCount; } public function purityIncrease(): float { $impurity = $this->impurity; if ($this->left() instanceof PurityNode) { $impurity -= $this->left()->impurity() * ($this->left()->samplesCount() / $this->samplesCount); } if ($this->right() instanceof PurityNode) { $impurity -= $this->right()->impurity() * ($this->right()->samplesCount() / $this->samplesCount); } return $impurity; } public function cleanup(): void { $this->groups = [[], []]; } }