Machine Learning

Tuning & Cross‑Validation

Tune carefully without leaking test data.

Cross-Validation

CV estimates performance more reliably than a single split, especially on small datasets.

Grid Search Example

from sklearn.model_selection import GridSearchCV
from sklearn.ensemble import RandomForestClassifier

grid = GridSearchCV(
  RandomForestClassifier(random_state=42),
  param_grid={"n_estimators":[200,500], "max_depth":[None, 5, 10]},
  cv=5,
  n_jobs=-1
)
grid.fit(X_train, y_train)
print("best:", grid.best_params_)