Skip to content

Grid Search

Introduction

The grid search explores the search space by starting from a corner and progressing step_size-steps per iteration. Increasing the step_size enables a more uniform exploration of the search space.

Example

from hyperactive.opt.gfo import GridSearch
from hyperactive.experiment.integrations import SklearnCvExperiment
from sklearn.svm import SVC
from sklearn.datasets import load_breast_cancer

# Load dataset
X, y = load_breast_cancer(return_X_y=True)

# Define search space
param_grid = {
    "C": [0.1, 1, 10],
    "gamma": ["scale", "auto"],
    "kernel": ["rbf", "linear"]
}

# Create experiment
experiment = SklearnCvExperiment(
    estimator=SVC(),
    param_grid=param_grid,
    X=X, y=y,
    cv=3
)

# Create optimizer with custom step size
optimizer = GridSearch(experiment=experiment, step_size=0.1)

# Run optimization
best_params = optimizer.solve()
print("Best parameters:", best_params)

About the implementation

The implementation of this grid-search was realized by Thomas Gak-Deluen and his team. The algorithm works by choosing a direction in the beginning and moving through the search space one 2-dimensional-plane at a time.

Parameters

step_size

The number of steps the grid search takes after each iteration. If this parameter is set to 3 the grid search won't select the next position, but the one it would normally select after 3 iterations. This way we get a sparse grid after the first pass through the search space. After the first pass is done the grid search starts at the beginning and does a second pass with the same step size. And a third pass after that.

  • type: int
  • default: 1
  • typical range: 1 ... 1000