implement Tranformer interface on preprocessing classes

This commit is contained in:
Arkadiusz Kondas 2016-06-16 10:03:57 +02:00
parent 7c5e79d2c6
commit d21a401365
5 changed files with 14 additions and 15 deletions

View File

@ -41,7 +41,7 @@ class Imputer implements Preprocessor
/** /**
* @param array $samples * @param array $samples
*/ */
public function preprocess(array &$samples) public function transform(array &$samples)
{ {
foreach ($samples as &$sample) { foreach ($samples as &$sample) {
$this->preprocessSample($sample, $samples); $this->preprocessSample($sample, $samples);

View File

@ -33,7 +33,7 @@ class Normalizer implements Preprocessor
/** /**
* @param array $samples * @param array $samples
*/ */
public function preprocess(array &$samples) public function transform(array &$samples)
{ {
$method = sprintf('normalizeL%s', $this->norm); $method = sprintf('normalizeL%s', $this->norm);
foreach ($samples as &$sample) { foreach ($samples as &$sample) {

View File

@ -4,10 +4,9 @@ declare (strict_types = 1);
namespace Phpml\Preprocessing; namespace Phpml\Preprocessing;
interface Preprocessor use Phpml\Transformer;
interface Preprocessor extends Transformer
{ {
/**
* @param array $samples
*/
public function preprocess(array &$samples);
} }

View File

@ -28,7 +28,7 @@ class ImputerTest extends \PHPUnit_Framework_TestCase
]; ];
$imputer = new Imputer(null, new MeanStrategy(), Imputer::AXIS_COLUMN); $imputer = new Imputer(null, new MeanStrategy(), Imputer::AXIS_COLUMN);
$imputer->preprocess($data); $imputer->transform($data);
$this->assertEquals($imputeData, $data, '', $delta = 0.01); $this->assertEquals($imputeData, $data, '', $delta = 0.01);
} }
@ -50,7 +50,7 @@ class ImputerTest extends \PHPUnit_Framework_TestCase
]; ];
$imputer = new Imputer(null, new MeanStrategy(), Imputer::AXIS_ROW); $imputer = new Imputer(null, new MeanStrategy(), Imputer::AXIS_ROW);
$imputer->preprocess($data); $imputer->transform($data);
$this->assertEquals($imputeData, $data, '', $delta = 0.01); $this->assertEquals($imputeData, $data, '', $delta = 0.01);
} }
@ -72,7 +72,7 @@ class ImputerTest extends \PHPUnit_Framework_TestCase
]; ];
$imputer = new Imputer(null, new MedianStrategy(), Imputer::AXIS_COLUMN); $imputer = new Imputer(null, new MedianStrategy(), Imputer::AXIS_COLUMN);
$imputer->preprocess($data); $imputer->transform($data);
$this->assertEquals($imputeData, $data, '', $delta = 0.01); $this->assertEquals($imputeData, $data, '', $delta = 0.01);
} }
@ -94,7 +94,7 @@ class ImputerTest extends \PHPUnit_Framework_TestCase
]; ];
$imputer = new Imputer(null, new MedianStrategy(), Imputer::AXIS_ROW); $imputer = new Imputer(null, new MedianStrategy(), Imputer::AXIS_ROW);
$imputer->preprocess($data); $imputer->transform($data);
$this->assertEquals($imputeData, $data, '', $delta = 0.01); $this->assertEquals($imputeData, $data, '', $delta = 0.01);
} }
@ -118,7 +118,7 @@ class ImputerTest extends \PHPUnit_Framework_TestCase
]; ];
$imputer = new Imputer(null, new MostFrequentStrategy(), Imputer::AXIS_COLUMN); $imputer = new Imputer(null, new MostFrequentStrategy(), Imputer::AXIS_COLUMN);
$imputer->preprocess($data); $imputer->transform($data);
$this->assertEquals($imputeData, $data); $this->assertEquals($imputeData, $data);
} }
@ -142,7 +142,7 @@ class ImputerTest extends \PHPUnit_Framework_TestCase
]; ];
$imputer = new Imputer(null, new MostFrequentStrategy(), Imputer::AXIS_ROW); $imputer = new Imputer(null, new MostFrequentStrategy(), Imputer::AXIS_ROW);
$imputer->preprocess($data); $imputer->transform($data);
$this->assertEquals($imputeData, $data); $this->assertEquals($imputeData, $data);
} }

View File

@ -31,7 +31,7 @@ class NormalizerTest extends \PHPUnit_Framework_TestCase
]; ];
$normalizer = new Normalizer(); $normalizer = new Normalizer();
$normalizer->preprocess($samples); $normalizer->transform($samples);
$this->assertEquals($normalized, $samples, '', $delta = 0.01); $this->assertEquals($normalized, $samples, '', $delta = 0.01);
} }
@ -51,7 +51,7 @@ class NormalizerTest extends \PHPUnit_Framework_TestCase
]; ];
$normalizer = new Normalizer(Normalizer::NORM_L1); $normalizer = new Normalizer(Normalizer::NORM_L1);
$normalizer->preprocess($samples); $normalizer->transform($samples);
$this->assertEquals($normalized, $samples, '', $delta = 0.01); $this->assertEquals($normalized, $samples, '', $delta = 0.01);
} }