Theory of Intelligence
MACHINE LEARNING•Foundations•An End To End Ml Project•4.6 Train, Fine-Tune & Evaluate

Introduction

Train first models, compare them fairly with cross-validation, tune hyperparameters with grid and randomized search, and do the one-time final evaluation on the test set.

Introduction

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!