· Xiaojing Yang · Machine Learning · 2 min read

中文

Grid Search and Randomized Search

How to tune hyperparameters without confusing search effort with scientific evidence.

Core idea

Hyperparameter search is useful, but every extra trial is another chance to overfit validation data.

1. Parameters vs hyperparameters

Parameters are learned from data. Hyperparameters are chosen outside training: regularization strength, tree depth, learning rate, number of neighbors, batch size, or LoRA rank.

Search workflow
Define space
What values are allowed?
Choose strategy
Grid or random
Cross-validate
Score each setting
Select
Pick best validation setting
Test once
Use untouched test data

2. Grid vs random

MethodStrengthWeakness
Grid searchsystematic over small spacesexpensive, wastes trials
Randomized searchefficient in large spacesless exhaustive
Successive halvingallocates resources adaptivelymore moving parts

3. sklearn example

from sklearn.model_selection import GridSearchCV, RandomizedSearchCV

param_grid = {"C": [0.01, 0.1, 1, 10], "penalty": ["l2"]}
search = GridSearchCV(model, param_grid, cv=5, scoring="f1_macro")
search.fit(X_train, y_train)

4. AI/NLP connection

In NLP fine-tuning, hyperparameters include learning rate, batch size, epochs, warmup, dropout, rank, alpha, and decoding settings. A clean search log is part of research credibility.

Good report

State search space, budget, metric, validation protocol, and final test result.

Bad report

Only report the best number after many hidden trials.

Takeaway

Hyperparameter tuning is not a magic path to better models. It is controlled search under a fair evaluation protocol.

Interview pattern

When this appears in an interview, I would answer in four layers:

  1. give the short definition;
  2. explain the intuition;
  3. name the common failure mode;
  4. connect it to a real evaluation or deployment decision.

References

Share:
Back to Blog

Related Posts

View All Posts »
FoundationsMachine LearningEN

Metrics Beyond Accuracy

Accuracy is easy to understand, but often wrong for imbalanced, ranked, or cost-sensitive tasks.