Skip to content

Commit

Permalink
fix Pipeline transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
akondas committed Jun 16, 2016
1 parent d21a401 commit 26f2cba
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Phpml/Pipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function getEstimator()
public function train(array $samples, array $targets)
{
foreach ($this->transformers as $transformer) {
$samples = $transformer->transform($samples);
$transformer->transform($samples);
}

$this->estimator->train($samples, $targets);
Expand Down
32 changes: 32 additions & 0 deletions tests/Phpml/PipelineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Phpml\Classification\SVC;
use Phpml\FeatureExtraction\TfIdfTransformer;
use Phpml\Pipeline;
use Phpml\Preprocessing\Imputer;
use Phpml\Preprocessing\Normalizer;
use Phpml\Preprocessing\Imputer\Strategy\MostFrequentStrategy;

class PipelineTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -22,4 +25,33 @@ public function testPipelineConstruction()
$this->assertEquals($transformers, $pipeline->getTransformers());
$this->assertEquals($estimator, $pipeline->getEstimator());
}

public function testPipelineWorkflow()
{
$transformers = [
new Imputer(null, new MostFrequentStrategy()),
new Normalizer(),
];
$estimator = new SVC();

$samples = [
[1, -1, 2],
[2, 0, null],
[null, 1, -1],
];

$targets = [
4,
1,
4
];

$pipeline = new Pipeline($transformers, $estimator);
$pipeline->train($samples, $targets);

$predicted = $pipeline->predict([[0, 0, 0]]);

$this->assertEquals(4, $predicted[0]);
}

}

0 comments on commit 26f2cba

Please sign in to comment.