mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-24 13:57:33 +00:00
Fix pipeline transformers
This commit is contained in:
parent
998879b6fc
commit
b4b190de7f
@ -54,7 +54,7 @@ class Pipeline implements Estimator
|
||||
public function train(array $samples, array $targets): void
|
||||
{
|
||||
foreach ($this->transformers as $transformer) {
|
||||
$transformer->fit($samples);
|
||||
$transformer->fit($samples, $targets);
|
||||
$transformer->transform($samples);
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,8 @@ namespace Phpml\Tests;
|
||||
use Phpml\Classification\SVC;
|
||||
use Phpml\FeatureExtraction\TfIdfTransformer;
|
||||
use Phpml\FeatureExtraction\TokenCountVectorizer;
|
||||
use Phpml\FeatureSelection\ScoringFunction\ANOVAFValue;
|
||||
use Phpml\FeatureSelection\SelectKBest;
|
||||
use Phpml\ModelManager;
|
||||
use Phpml\Pipeline;
|
||||
use Phpml\Preprocessing\Imputer;
|
||||
@ -106,6 +108,18 @@ class PipelineTest extends TestCase
|
||||
$this->assertEquals($expected, $predicted);
|
||||
}
|
||||
|
||||
public function testPipelineTransformersWithTargets() : void
|
||||
{
|
||||
$samples = [[1, 2, 1], [1, 3, 4], [5, 2, 1], [1, 3, 3], [1, 3, 4], [0, 3, 5]];
|
||||
$targets = ['a', 'a', 'a', 'b', 'b', 'b'];
|
||||
|
||||
$pipeline = new Pipeline([$selector = new SelectKBest(2)], new SVC());
|
||||
$pipeline->train($samples, $targets);
|
||||
|
||||
self::assertEquals([1.47058823, 4.0, 3.0], $selector->scores(), '', 0.00000001);
|
||||
self::assertEquals(['b'], $pipeline->predict([[1, 3, 5]]));
|
||||
}
|
||||
|
||||
public function testSaveAndRestore(): void
|
||||
{
|
||||
$pipeline = new Pipeline([
|
||||
|
Loading…
Reference in New Issue
Block a user