transform samples for prediction in pipeline

This commit is contained in:
Arkadiusz Kondas 2016-06-16 16:10:46 +02:00
parent 26f2cbabc4
commit 7f4a0b243f
3 changed files with 14 additions and 7 deletions

View File

@ -67,10 +67,7 @@ class Pipeline implements Estimator
*/
public function train(array $samples, array $targets)
{
foreach ($this->transformers as $transformer) {
$transformer->transform($samples);
}
$this->transformSamples($samples);
$this->estimator->train($samples, $targets);
}
@ -81,6 +78,18 @@ class Pipeline implements Estimator
*/
public function predict(array $samples)
{
$this->transformSamples($samples);
return $this->estimator->predict($samples);
}
/**
* @param array $samples
*/
private function transformSamples(array &$samples)
{
foreach ($this->transformers as $transformer) {
$transformer->transform($samples);
}
}
}

View File

@ -8,5 +8,4 @@ use Phpml\Transformer;
interface Preprocessor extends Transformer
{
}

View File

@ -43,7 +43,7 @@ class PipelineTest extends \PHPUnit_Framework_TestCase
$targets = [
4,
1,
4
4,
];
$pipeline = new Pipeline($transformers, $estimator);
@ -53,5 +53,4 @@ class PipelineTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(4, $predicted[0]);
}
}