From 998879b6fca2f8a2e3e761724b606ee3594a78ac Mon Sep 17 00:00:00 2001 From: Arkadiusz Kondas Date: Wed, 14 Feb 2018 18:52:11 +0100 Subject: [PATCH] Switch SelectKBest constructor parameters --- src/FeatureSelection/SelectKBest.php | 2 +- tests/FeatureSelection/SelectKBestTest.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/FeatureSelection/SelectKBest.php b/src/FeatureSelection/SelectKBest.php index 8f4b273..bd84e73 100644 --- a/src/FeatureSelection/SelectKBest.php +++ b/src/FeatureSelection/SelectKBest.php @@ -31,7 +31,7 @@ final class SelectKBest implements Transformer */ private $keepColumns = null; - public function __construct(?ScoringFunction $scoringFunction = null, int $k = 10) + public function __construct(int $k = 10, ?ScoringFunction $scoringFunction = null) { if ($scoringFunction === null) { $scoringFunction = new ANOVAFValue(); diff --git a/tests/FeatureSelection/SelectKBestTest.php b/tests/FeatureSelection/SelectKBestTest.php index df17c08..ebf119b 100644 --- a/tests/FeatureSelection/SelectKBestTest.php +++ b/tests/FeatureSelection/SelectKBestTest.php @@ -18,7 +18,7 @@ final class SelectKBestTest extends TestCase { $samples = [[1, 2, 1], [1, 3, 4], [5, 2, 1], [1, 3, 3], [1, 3, 4], [0, 3, 5]]; $targets = ['a', 'a', 'a', 'b', 'b', 'b']; - $selector = new SelectKBest(null, 2); + $selector = new SelectKBest(2); $selector->fit($samples, $targets); $selector->transform($samples); @@ -29,7 +29,7 @@ final class SelectKBestTest extends TestCase { $samples = [[1, 2, 1], [1, 3, 4], [5, 2, 1], [1, 3, 3], [1, 3, 4], [0, 3, 5]]; $targets = ['a', 'a', 'a', 'b', 'b', 'b']; - $selector = new SelectKBest(null, 4); + $selector = new SelectKBest(4); $selector->fit($samples, $targets); $selector->transform($samples); @@ -39,7 +39,7 @@ final class SelectKBestTest extends TestCase public function testSelectKBestWithIrisDataset(): void { $dataset = new IrisDataset(); - $selector = new SelectKBest(new ANOVAFValue(), 2); + $selector = new SelectKBest(2, new ANOVAFValue()); $selector->fit($samples = $dataset->getSamples(), $dataset->getTargets()); $selector->transform($samples); @@ -51,7 +51,7 @@ final class SelectKBestTest extends TestCase $samples = [[73676, 1996, 2], [77006, 1998, 5], [10565, 2000, 4], [146088, 1995, 2], [15000, 2001, 2], [65940, 2000, 2], [9300, 2000, 2], [93739, 1996, 2], [153260, 1994, 2], [17764, 2002, 2], [57000, 1998, 2], [15000, 2000, 2]]; $targets = [2000, 2750, 15500, 960, 4400, 8800, 7100, 2550, 1025, 5900, 4600, 4400]; - $selector = new SelectKBest(new UnivariateLinearRegression(), 2); + $selector = new SelectKBest(2, new UnivariateLinearRegression()); $selector->fit($samples, $targets); $selector->transform($samples); @@ -64,14 +64,14 @@ final class SelectKBestTest extends TestCase public function testThrowExceptionOnEmptyTargets(): void { $this->expectException(InvalidArgumentException::class); - $selector = new SelectKBest(new ANOVAFValue(), 2); + $selector = new SelectKBest(2, new ANOVAFValue()); $selector->fit([[1, 2, 3], [4, 5, 6]], []); } public function testThrowExceptionWhenNotTrained(): void { $this->expectException(InvalidOperationException::class); - $selector = new SelectKBest(new ANOVAFValue(), 2); + $selector = new SelectKBest(2, new ANOVAFValue()); $selector->scores(); } }