mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-25 22:37:34 +00:00
implement Tranformer interface on preprocessing classes
This commit is contained in:
parent
7c5e79d2c6
commit
d21a401365
@ -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);
|
||||||
|
@ -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) {
|
||||||
|
@ -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);
|
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user