mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-25 14:27:34 +00:00
add more tests for fit metod in preprocessors
This commit is contained in:
parent
3e9e70810d
commit
be7423350f
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user