Skip to main content
. 2023 Jun 23;23(13):5850. doi: 10.3390/s23135850
Algorithm 3 Exhaustive Grid Search for Hyperparameter Optimization
  •   1:

    procedure GridSearch(model,param_grid,dataset,scoring,cv)

  •   2:

        Preprocess dataset

  •   3:

        Split dataset into train_set and test_set

  •   4:

        Initialize best_score

  •   5:

        Initialize best_params

  •   6:

        for all combinations params in param_grid do

  •   7:

              model Instantiate model with params

  •   8:

              scores Perform cv-fold cross-validation on train_set with model

  •   9:

              avg_score Average scores

  • 10:

              if avg_score>best_score then

  • 11:

                   best_scoreavg_score

  • 12:

                   best_paramsparams

  • 13:

              end if

  • 14:

        end for

  • 15:

        Train model with best_params on entire train_set

  • 16:

        Evaluate model on test_set using scoring metric

  • 17:

        return model, best_params

  • 18:

    end procedure