mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2025-02-03 04:28:33 +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)
|
public function train(array $samples, array $targets)
|
||||||
{
|
{
|
||||||
foreach ($this->transformers as $transformer) {
|
$this->transformSamples($samples);
|
||||||
$transformer->transform($samples);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->estimator->train($samples, $targets);
|
$this->estimator->train($samples, $targets);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,6 +78,18 @@ class Pipeline implements Estimator
|
|||||||
*/
|
*/
|
||||||
public function predict(array $samples)
|
public function predict(array $samples)
|
||||||
{
|
{
|
||||||
|
$this->transformSamples($samples);
|
||||||
|
|
||||||
return $this->estimator->predict($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
|
interface Preprocessor extends Transformer
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ class PipelineTest extends \PHPUnit_Framework_TestCase
|
|||||||
$targets = [
|
$targets = [
|
||||||
4,
|
4,
|
||||||
1,
|
1,
|
||||||
4
|
4,
|
||||||
];
|
];
|
||||||
|
|
||||||
$pipeline = new Pipeline($transformers, $estimator);
|
$pipeline = new Pipeline($transformers, $estimator);
|
||||||
@ -53,5 +53,4 @@ class PipelineTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertEquals(4, $predicted[0]);
|
$this->assertEquals(4, $predicted[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user