mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2025-01-23 23:28:24 +00:00
transform samples for prediction in pipeline
This commit is contained in:
parent
26f2cbabc4
commit
7f4a0b243f
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,5 +8,4 @@ use Phpml\Transformer;
|
||||
|
||||
interface Preprocessor extends Transformer
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -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]);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user