1<span style="float:right;"><a href="https://github.com/RubixML/ML/blob/master/src/GridSearch.php">[source]</a></span> 2 3# Grid Search 4Grid Search is an algorithm that optimizes hyper-parameter selection. From the user's perspective, the process of training and predicting is the same, however, under the hood Grid Search trains a model for each combination of possible parameters and the best model is selected as the base estimator. 5 6**Interfaces:** [Wrapper](wrapper.md), [Estimator](estimator.md), [Learner](learner.md), [Parallel](parallel.md), [Persistable](persistable.md), [Verbose](verbose.md) 7 8**Data Type Compatibility:** Depends on base learner 9 10## Parameters 11| # | Name | Default | Type | Description | 12|---|---|---|---|---| 13| 1 | base | | string | The class name of the base learner. | 14| 2 | params | | array | An array of [n-tuples](faq.md#what-is-a-tuple) containing the possible values for each of the base learner's constructor parameters. | 15| 3 | metric | null | Metric | The validation metric used to score each set of hyper-parameters. If null, automatically selects a default metric based on estimator type. | 16| 4 | validator | KFold | Validator | The validator used to test and score each trained model. | 17 18## Example 19```php 20use Rubix\ML\GridSearch; 21use Rubix\ML\Classifiers\KNearestNeighbors; 22use Rubix\ML\Kernels\Distance\Euclidean; 23use Rubix\ML\Kernels\Distance\Manhattan; 24use Rubix\ML\CrossValidation\Metrics\FBeta; 25use Rubix\ML\CrossValidation\KFold; 26 27$params = [ 28 [1, 3, 5, 10], [true, false], [new Euclidean(), new Manhattan()], 29]; 30 31$estimator = new GridSearch(KNearestNeighbors::class, $params, new FBeta(), new KFold(5)); 32``` 33 34## Additional Methods 35Return an array containing the validation scores and hyper-parameters under test for each combination resulting from the last search: 36```php 37public results() : ?array 38``` 39 40Return an array containing the best parameters from the last search: 41```php 42public best() : ?array 43``` 44 45```php 46 47var_dump($estimator->best()); 48``` 49 50```sh 51array(3) { 52 [0]=> int(3) 53 [1]=> bool(true) 54 [2]=> object(Rubix\ML\Kernels\Distance\Manhattan) {} 55} 56```