Skip to content

Commit

Permalink
Fix Grid Search best model selection
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdalpino committed Dec 6, 2022
1 parent cc27290 commit 3e23ef4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
- 1.3.5
- Fix Grid Search best model selection

- 1.3.4
- Fix Decision Tree max height terminating condition

Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@
"config": {
"preferred-install": "dist",
"sort-packages": true,
"process-timeout": 3000
"process-timeout": 3000,
"allow-plugins": {
"phpstan/extension-installer": true
}
},
"funding": [
{
Expand Down
2 changes: 1 addition & 1 deletion src/GridSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public function train(Dataset $dataset) : void

$scores = $this->backend->process();

array_multisort($scores, $combinations, SORT_DESC);
array_multisort($scores, SORT_DESC, $combinations);

$best = reset($combinations) ?: [];

Expand Down
8 changes: 8 additions & 0 deletions tests/GridSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,13 @@ public function trainPredictBest() : void
$score = $this->metric->score($predictions, $testing->labels());

$this->assertGreaterThanOrEqual(self::MIN_SCORE, $score);

$expectedBest = [
'k' => 10,
'weighted' => true,
'kernel' => new Manhattan(),
];

$this->assertEquals($expectedBest, $this->estimator->base()->params());
}
}

0 comments on commit 3e23ef4

Please sign in to comment.