Grid Search Steps and Example
Grid Search Steps and Example
Grid search is a hyperparameter tuning technique used in machine learning to identify the best combination of
hyperparameters for a model. It systematically evaluates all possible combinations of hyperparameter values to
find the optimal set based on a scoring metric.
Process**:
```python
param_grid = {
'C': [0.1, 1, 10],
'kernel': ['linear', 'rbf'],
'gamma': [0.001, 0.01, 0.1]
}
python
from sklearn.model_selection import GridSearchCV
from sklearn.svm import SVC
grid_search = GridSearchCV(SVC(), param_grid, cv=5, scoring='accuracy')
grid_search.fit(X_train, y_train)
Retrieve the best parameters:
python code:
print("Best parameters:", grid_search.best_params_)
Output might be:
Best parameters: {'C': 10, 'gamma': 0.01, 'kernel': 'rbf'}
Evaluate the model with the best parameters on the test set.
This approach ensures that the model is fine-tuned to achieve the best performance for the given task.