Theory of Intelligence
4.6 Train, Fine-Tune & Evaluate•Concept 1 of 4

Introduction

lightbulb

Book reference: Géron, Hands-On Machine Learning, Ch. 2 ("Select and Train a Model", "Fine-Tune Your Model", "Evaluate Your System on the Test Set"). Written in our own words.

We have a framed problem, a clean training set and a preprocessing pipeline. Now comes the part most people think of as "machine learning": training models. It is actually the easy part — thanks to all the preparation, each model is just a few lines of code.

The process:

  1. Train a few quick models and compare them fairly with cross-validation.
  2. Shortlist the 2–5 most promising.
  3. Fine-tune their hyperparameters.
  4. Evaluate the final model once on the test set.
PYTHON
import numpy as np
from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler

df = fetch_california_housing(as_frame=True).frame
train_set, test_set = train_test_split(df, test_size=0.2, random_state=42)
X_train, y_train = train_set.drop(columns="MedHouseVal"), train_set["MedHouseVal"]
X_test, y_test = test_set.drop(columns="MedHouseVal"), test_set["MedHouseVal"]

Discuss theoretical concepts, mathematical formulas, and architectural foundations.

Supports inline code with `backticks`
No comments yet. Be the first to start the discussion!