10 Automl Hpo

Chapter 09: AutoML β€” Automated Machine LearningπŸ”—

"AutoML democratizes ML β€” automating the tedious parts so experts can focus on strategy."


9.1 What is AutoML?πŸ”—

AutoML (Automated Machine Learning) automates the process of selecting, training, and tuning machine learning models. Instead of manually trying different algorithms and hyperparameters, AutoML explores the entire search space automatically.

Manual ML vs AutoMLπŸ”—

MANUAL ML:
  Data β†’ You pick algorithm β†’ You tune hyperparameters β†’ You evaluate β†’ Repeat
  Time: Days to weeks

AUTOML:
  Data β†’ AutoML searches algorithms + hyperparameters β†’ Best model returned
  Time: Hours to days (with less human effort)

9.2 What AutoML AutomatesπŸ”—

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              AUTOML AUTOMATION SCOPE                    β”‚
β”‚                                                         β”‚
β”‚  βœ… Feature Preprocessing (encoding, scaling, imputing) β”‚
β”‚  βœ… Algorithm Selection (RF, XGB, SVM, Neural Net...)   β”‚
β”‚  βœ… Hyperparameter Optimization (HPO)                   β”‚
β”‚  βœ… Model Ensembling (stack best models)                β”‚
β”‚  βœ… Neural Architecture Search (NAS)                    β”‚
β”‚  βœ… Model Evaluation & Comparison                       β”‚
β”‚  βœ… Cross-validation strategy                           β”‚
β”‚                                                         β”‚
β”‚  ❌ NOT automated: Problem definition, data collection  β”‚
β”‚     business metrics, deployment decisions              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

9.3 AutoML Search ProcessπŸ”—

                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚     AUTOML SEARCH        β”‚
                    β”‚                          β”‚
  Input Data ──────▢│  Algorithm Space:        β”‚
                    β”‚  β”œβ”€β”€ Random Forest       β”‚
                    β”‚  β”œβ”€β”€ Gradient Boosting   β”‚
                    β”‚  β”œβ”€β”€ SVM                 β”‚
                    β”‚  β”œβ”€β”€ Neural Networks     β”‚
                    β”‚  └── Linear Models       β”‚
                    β”‚                          β”‚
                    β”‚  Hyperparameter Space:   β”‚
                    β”‚  β”œβ”€β”€ learning_rate       β”‚
                    β”‚  β”œβ”€β”€ max_depth           β”‚
                    β”‚  β”œβ”€β”€ n_estimators        β”‚
                    β”‚  └── dropout_rate        β”‚
                    β”‚                          β”‚
                    β”‚  Search Strategy:        β”‚
                    β”‚  β”œβ”€β”€ Bayesian Opt        β”‚
                    β”‚  β”œβ”€β”€ Random Search       β”‚
                    β”‚  └── Evolutionary        β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
                                 β–Ό
                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                         β”‚  Best Model   β”‚
                         β”‚  + Config     β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

9.4 Hyperparameter Optimization (HPO)πŸ”—

Hyperparameters are settings you choose before training (not learned by the model).

HPO Strategies ComparedπŸ”—

GRID SEARCH:                     RANDOM SEARCH:
β”Œβ”€β”€β”¬β”€β”€β”¬β”€β”€β”¬β”€β”€β”¬β”€β”€β”                 β”Œβ”€β”€β”¬β”€β”€β”¬β”€β”€β”¬β”€β”€β”¬β”€β”€β”
β”‚  β”‚  β”‚  β”‚  β”‚  β”‚                 β”‚  β”‚  β”‚βœ“ β”‚  β”‚  β”‚
β”œβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”€                 β”œβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”€
β”‚  β”‚  β”‚  β”‚  β”‚  β”‚                 β”‚  β”‚  β”‚  β”‚βœ“ β”‚  β”‚
β”œβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”€                 β”œβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”€
β”‚  β”‚  β”‚  β”‚  β”‚  β”‚                 β”‚βœ“ β”‚  β”‚  β”‚  β”‚  β”‚
β””β”€β”€β”΄β”€β”€β”΄β”€β”€β”΄β”€β”€β”΄β”€β”€β”˜                 β””β”€β”€β”΄β”€β”€β”΄β”€β”€β”΄β”€β”€β”΄β”€β”€β”˜
Tests every combo                 Random samples
Slow, exhaustive                  Faster, misses some

BAYESIAN OPTIMIZATION (BEST):
Start β†’ Try 5 random points β†’ Build a model of "which areas are good"
      β†’ Sample from good areas β†’ Update model β†’ Repeat
  β†’ Smart, efficient, finds optimum faster

HPO with Optuna (Python)πŸ”—

import optuna
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import cross_val_score

def objective(trial):
    # Define hyperparameter search space
    params = {
        'n_estimators': trial.suggest_int('n_estimators', 50, 500),
        'max_depth': trial.suggest_int('max_depth', 3, 20),
        'min_samples_split': trial.suggest_int('min_samples_split', 2, 20),
        'max_features': trial.suggest_categorical('max_features', ['sqrt', 'log2']),
    }

    clf = RandomForestClassifier(**params, random_state=42)
    score = cross_val_score(clf, X_train, y_train, cv=5, scoring='accuracy').mean()
    return score

# Run optimization (100 trials)
study = optuna.create_study(direction='maximize')
study.optimize(objective, n_trials=100)

print(f"Best accuracy: {study.best_value:.4f}")
print(f"Best params: {study.best_params}")

9.5 Vertex AI AutoML (GCP)πŸ”—

Vertex AI AutoML lets you train high-quality models without writing ML code.

Supported AutoML TypesπŸ”—

Task What You Provide What You Get
AutoML Tables Tabular CSV data Classification/Regression model
AutoML Vision Labeled images Image classifier
AutoML NLP Labeled text Text classifier
AutoML Video Labeled videos Video classifier

AutoML Tables WorkflowπŸ”—

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           VERTEX AI AUTOML TABLES WORKFLOW           β”‚
β”‚                                                      β”‚
β”‚  1. Upload CSV to BigQuery or GCS                    β”‚
β”‚        β”‚                                             β”‚
β”‚        β–Ό                                             β”‚
β”‚  2. Create Dataset in Vertex AI                      β”‚
β”‚        β”‚                                             β”‚
β”‚        β–Ό                                             β”‚
β”‚  3. Configure target column + training budget        β”‚
β”‚     (e.g., 1 hour, 8 hours, 24 hours)                β”‚
β”‚        β”‚                                             β”‚
β”‚        β–Ό                                             β”‚
β”‚  4. AutoML trains 100s of models internally          β”‚
β”‚     (feature engineering + HPO + ensembling)         β”‚
β”‚        β”‚                                             β”‚
β”‚        β–Ό                                             β”‚
β”‚  5. Evaluate: AUC, Precision, Recall, Confusion Mat  β”‚
β”‚        β”‚                                             β”‚
β”‚        β–Ό                                             β”‚
β”‚  6. Deploy best model to Vertex AI Endpoint          β”‚
β”‚        β”‚                                             β”‚
β”‚        β–Ό                                             β”‚
β”‚  7. Online predictions via REST API                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Vertex AI AutoML via Python SDKπŸ”—

from google.cloud import aiplatform

aiplatform.init(project="my-project", location="us-central1")

# Create a Dataset from BigQuery
dataset = aiplatform.TabularDataset.create(
    display_name="customer-churn-dataset",
    bq_source="bq://my-project.ml_datasets.customer_churn",
)

# Train AutoML Tabular model
job = aiplatform.AutoMLTabularTrainingJob(
    display_name="churn-automl-v1",
    optimization_prediction_type="classification",   # or 'regression'
    optimization_objective="maximize-au-roc",
)

model = job.run(
    dataset=dataset,
    target_column="churned",            # column to predict
    training_fraction_split=0.8,
    validation_fraction_split=0.1,
    test_fraction_split=0.1,
    budget_milli_node_hours=1000,       # 1 hour of training budget
    model_display_name="churn-model-v1",
)

# Deploy
endpoint = model.deploy(machine_type="n1-standard-2")

# Predict
prediction = endpoint.predict(instances=[{
    "age": 35,
    "tenure_months": 12,
    "monthly_charges": 65.5
}])
print(prediction.predictions)

9.6 Neural Architecture Search (NAS)πŸ”—

NAS automates the design of neural network architectures (layer types, depths, connections).

TRADITIONAL: Data Scientist manually designs network architecture
  β”Œβ”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”
  β”‚Conv│─│Conv│─│Pool│─│FC  │─│Softβ”‚  (hand-designed)
  β””β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”˜

NAS: Algorithm searches for best architecture
  Search Space: [Conv3x3, Conv5x5, Pool, Skip, Dense, ...]
       β”‚
       β”œβ”€β”€ Try Architecture 1 β†’ eval β†’ 0.82 accuracy
       β”œβ”€β”€ Try Architecture 2 β†’ eval β†’ 0.85 accuracy
       β”œβ”€β”€ Try Architecture N β†’ eval β†’ 0.91 accuracy ← WINNER
       └── Return best architecture

Library Best For Notes
Vertex AI AutoML GCP production workloads Fully managed, no code
H2O AutoML Tabular data, fast Open source
TPOT Sklearn pipeline optimization Uses genetic algorithms
AutoKeras Deep learning architectures Keras/TF-based
Optuna HPO only Flexible, widely used
Ray Tune Distributed HPO Scales to clusters

9.8 AutoML in the MLOps PipelineπŸ”—

MLOps Pipeline with AutoML:

  New Data Arrives
       β”‚
       β–Ό
  Data Validation
       β”‚
       β–Ό
  Trigger AutoML Training (Vertex AI)
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚  AutoML internally:             β”‚
  β”‚  - Tries 100s of configs        β”‚
  β”‚  - Logs all experiments         β”‚
  β”‚  - Returns best model           β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
                 β–Ό
  Evaluate vs current prod model
       β”‚
       β”œβ”€β”€ Better? β†’ Deploy (CI/CD)
       └── Worse?  β†’ Alert team

Next Chapter β†’ 10: Experiment Tracking