From be7423350fea4a5a2f6c7fe9dd88509125172559 Mon Sep 17 00:00:00 2001 From: Arkadiusz Kondas Date: Fri, 17 Jun 2016 00:23:27 +0200 Subject: [PATCH] add more tests for fit metod in preprocessors --- tests/Phpml/Preprocessing/ImputerTest.php | 27 ++++++++++++++++++++ tests/Phpml/Preprocessing/NormalizerTest.php | 25 ++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/tests/Phpml/Preprocessing/ImputerTest.php b/tests/Phpml/Preprocessing/ImputerTest.php index 9aa3ea3..fce195b 100644 --- a/tests/Phpml/Preprocessing/ImputerTest.php +++ b/tests/Phpml/Preprocessing/ImputerTest.php @@ -146,4 +146,31 @@ class ImputerTest extends \PHPUnit_Framework_TestCase $this->assertEquals($imputeData, $data); } + + public function testImputerWorksOnFitSamples() + { + $trainData = [ + [1, 3, 4], + [6, 7, 8], + [8, 7, 5], + ]; + + $data = [ + [1, 3, null], + [6, null, 8], + [null, 7, 5], + ]; + + $imputeData = [ + [1, 3, 5.66], + [6, 5.66, 8], + [5, 7, 5], + ]; + + $imputer = new Imputer(null, new MeanStrategy(), Imputer::AXIS_COLUMN, $trainData); + $imputer->transform($data); + + $this->assertEquals($imputeData, $data, '', $delta = 0.01); + } + } diff --git a/tests/Phpml/Preprocessing/NormalizerTest.php b/tests/Phpml/Preprocessing/NormalizerTest.php index cd007fb..d01e62c 100644 --- a/tests/Phpml/Preprocessing/NormalizerTest.php +++ b/tests/Phpml/Preprocessing/NormalizerTest.php @@ -55,4 +55,29 @@ class NormalizerTest extends \PHPUnit_Framework_TestCase $this->assertEquals($normalized, $samples, '', $delta = 0.01); } + + public function testFitNotChangeNormalizerBehavior() + { + $samples = [ + [1, -1, 2], + [2, 0, 0], + [0, 1, -1], + ]; + + $normalized = [ + [0.4, -0.4, 0.81], + [1.0, 0.0, 0.0], + [0.0, 0.7, -0.7], + ]; + + $normalizer = new Normalizer(); + $normalizer->transform($samples); + + $this->assertEquals($normalized, $samples, '', $delta = 0.01); + + $normalizer->fit($samples); + + $this->assertEquals($normalized, $samples, '', $delta = 0.01); + } + }