MDL-65769 lib: update PHP-ML to 0.8.0
This commit is contained in:
@@ -7,9 +7,9 @@ namespace Phpml;
|
||||
class Pipeline implements Estimator
|
||||
{
|
||||
/**
|
||||
* @var array|Transformer[]
|
||||
* @var Transformer[]
|
||||
*/
|
||||
private $transformers;
|
||||
private $transformers = [];
|
||||
|
||||
/**
|
||||
* @var Estimator
|
||||
@@ -17,8 +17,7 @@ class Pipeline implements Estimator
|
||||
private $estimator;
|
||||
|
||||
/**
|
||||
* @param array|Transformer[] $transformers
|
||||
* @param Estimator $estimator
|
||||
* @param Transformer[] $transformers
|
||||
*/
|
||||
public function __construct(array $transformers, Estimator $estimator)
|
||||
{
|
||||
@@ -29,52 +28,40 @@ class Pipeline implements Estimator
|
||||
$this->estimator = $estimator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Transformer $transformer
|
||||
*/
|
||||
public function addTransformer(Transformer $transformer)
|
||||
public function addTransformer(Transformer $transformer): void
|
||||
{
|
||||
$this->transformers[] = $transformer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Estimator $estimator
|
||||
*/
|
||||
public function setEstimator(Estimator $estimator)
|
||||
public function setEstimator(Estimator $estimator): void
|
||||
{
|
||||
$this->estimator = $estimator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|Transformer[]
|
||||
* @return Transformer[]
|
||||
*/
|
||||
public function getTransformers()
|
||||
public function getTransformers(): array
|
||||
{
|
||||
return $this->transformers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Estimator
|
||||
*/
|
||||
public function getEstimator()
|
||||
public function getEstimator(): Estimator
|
||||
{
|
||||
return $this->estimator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $samples
|
||||
* @param array $targets
|
||||
*/
|
||||
public function train(array $samples, array $targets)
|
||||
public function train(array $samples, array $targets): void
|
||||
{
|
||||
$this->fitTransformers($samples);
|
||||
$this->transformSamples($samples);
|
||||
foreach ($this->transformers as $transformer) {
|
||||
$transformer->fit($samples, $targets);
|
||||
$transformer->transform($samples);
|
||||
}
|
||||
|
||||
$this->estimator->train($samples, $targets);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $samples
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function predict(array $samples)
|
||||
@@ -84,20 +71,7 @@ class Pipeline implements Estimator
|
||||
return $this->estimator->predict($samples);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $samples
|
||||
*/
|
||||
private function fitTransformers(array &$samples)
|
||||
{
|
||||
foreach ($this->transformers as $transformer) {
|
||||
$transformer->fit($samples);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $samples
|
||||
*/
|
||||
private function transformSamples(array &$samples)
|
||||
private function transformSamples(array &$samples): void
|
||||
{
|
||||
foreach ($this->transformers as $transformer) {
|
||||
$transformer->transform($samples);
|
||||
|
||||
Reference in New Issue
Block a user