0/70 completed
Machine Learning Interactive

Hyperparameter Tuning

Find optimal model settings. Grid search is exhaustive, random search is efficient, Bayesian optimization learns from past trials.

๐Ÿ“Š Parameters vs Hyperparameters

Parameters

Learned from data during training

  • โ€ข Neural network weights
  • โ€ข Regression coefficients
  • โ€ข Tree split thresholds

Hyperparameters

Set before training, control learning

  • โ€ข Learning rate, regularization
  • โ€ข Number of trees, max depth
  • โ€ข Number of layers, neurons

Search Parameters

Parameter Range 10
5 20
Grid Points 5
3 15
Random Trials 20
5 50

๐Ÿ“Š Search Results

Grid Search 0.868
5 trials
Random Search 0.872
20 trials
Bayesian 0.844
10 trials (most efficient)

Validation Curve

Training score: Always improves (overfitting)
Validation score: Peaks at optimal

Search Method Comparison

Grid Search

โœ“ Exhaustive, reproducible

โœ— Exponential in dims

Best for: โ‰ค3 hyperparams

Random Search

โœ“ Efficient in high dims

โœ— No learning

Best for: Many hyperparams

Bayesian

โœ“ Learns from trials

โœ— Overhead, sequential

Best for: Expensive evaluations

๐Ÿˆ Hyperparameters in Betting Models

XGBoost

max_depth, learning_rate, n_estimators, reg_lambda

Neural Net

layers, neurons, dropout, batch_size

Elo System

K-factor, home advantage, initial rating

Kelly

Fraction (full/half/quarter), bankroll

R Code Equivalent

# Hyperparameter tuning with caret
library(caret)

# Grid search
grid <- expand.grid(
  nrounds = c(50, 100, 150),
  max_depth = c(3, 5, 7),
  eta = c(0.01, 0.1, 0.3),
  gamma = 0,
  colsample_bytree = 0.8,
  min_child_weight = 1,
  subsample = 0.8
)

ctrl <- trainControl(
  method = "cv",
  number = 5,
  search = "grid"
)

# Train with grid search
model <- train(
  y ~ ., data = train_data,
  method = "xgbTree",
  trControl = ctrl,
  tuneGrid = grid
)

# Random search alternative
ctrl_random <- trainControl(
  method = "cv",
  number = 5,
  search = "random"
)

model_random <- train(
  y ~ ., data = train_data,
  method = "xgbTree",
  trControl = ctrl_random,
  tuneLength = 20
)

# Best hyperparameters
print(model$bestTune)

โœ… Key Takeaways

  • โ€ข Hyperparameters control the learning process
  • โ€ข Grid search: exhaustive but slow
  • โ€ข Random search: efficient in high dimensions
  • โ€ข Bayesian: learns from past trials
  • โ€ข Always use validation set, not training
  • โ€ข Cross-validation for robust estimates

Pricing Models & Frameworks Tutorial

Built for mastery ยท Interactive learning