addTransformer($transformer); } $this->estimator = $estimator; } public function addTransformer(Transformer $transformer): void { $this->transformers[] = $transformer; } public function setEstimator(Estimator $estimator): void { $this->estimator = $estimator; } /** * @return Transformer[] */ public function getTransformers(): array { return $this->transformers; } public function getEstimator(): Estimator { return $this->estimator; } public function train(array $samples, array $targets): void { foreach ($this->transformers as $transformer) { $transformer->fit($samples, $targets); $transformer->transform($samples); } $this->estimator->train($samples, $targets); } /** * @return mixed */ public function predict(array $samples) { $this->transformSamples($samples); return $this->estimator->predict($samples); } private function transformSamples(array &$samples): void { foreach ($this->transformers as $transformer) { $transformer->transform($samples); } } }