add more tests for fit metod in preprocessors

This commit is contained in:
Arkadiusz Kondas 2016-06-17 00:23:27 +02:00
parent 3e9e70810d
commit be7423350f
2 changed files with 52 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}