Lab notebooks

Eleven notebooks, one per taught chapter, each living beside the deck it accompanies in Chapters/chapter_NN/chapter_NN_lab.ipynb — one lab per deck, both precourse sessions included.

Each mirrors its chapter’s Python lab and closes with worked solutions to that chapter’s exercises. Every chapter, without exception: these are the labs the course is built around.

Several also check the deck’s by-hand arithmetic in code — the [Math] exercises whose answers a student would otherwise have to take on trust. Chapter 2 classifies the six-point KNN query and watches the prediction flip between \(K=1\) and \(K=3\); chapter 5 confirms the \(1 - 1/e\) bootstrap inclusion probability by simulation; chapter 6 counts the \(2^{p}\) models best-subset selection would need; chapter 7 takes the rank of a spline basis to show a cubic spline with \(K\) knots has \(K+4\) degrees of freedom; chapter 8 shows Gini separating two splits that classification error scores identically; chapter 10 reproduces the 931-parameter count and the convolution arithmetic. Where the deck asserts a number, the lab computes it.

Each notebook runs locally or on Google Colab; data loads via the ISLP package with an automatic fallback to the bundled CSVs, so nothing needs downloading by hand. Colab is the recommended route — nothing to install.

Every notebook is rendered in full below (with its stored outputs — the documentation build never executes them).

11 labs (with solutions) one lab per deck runs locally and on Colab

The ten labs

Ch.

Lab

Read here

Open in Colab

0 · Precourse (a) — Statistics

chapter_00_lab.ipynb

Rendered

Colab

0b · Precourse (b) — Toolkit

chapter_00b_lab.ipynb

Rendered

Colab

1 · Introduction

chapter_01_lab.ipynb

Rendered

Colab

2 · Statistical Learning

chapter_02_lab.ipynb

Rendered

Colab

3 · Linear Regression

chapter_03_lab.ipynb

Rendered

Colab

4 · Classification

chapter_04_lab.ipynb

Rendered

Colab

5 · Resampling Methods

chapter_05_lab.ipynb

Rendered

Colab

6 · Model Selection & Regularization

chapter_06_lab.ipynb

Rendered

Colab

7 · Moving Beyond Linearity

chapter_07_lab.ipynb

Rendered

Colab

8 · Tree-Based Methods

chapter_08_lab.ipynb

Rendered

Colab

The labs for support vector machines, survival analysis, unsupervised learning and multiple testing moved with their decks into the self-study advanced modules (A5, A6, A8, A7).

Tip

The Colab badges open straight from the public GitHub repository; a Google account is all you need to run a notebook.

How the notebooks find their data

Each notebook opens with a setup cell that:

  1. detects whether it is running on Colab and installs any missing packages (ISLP, plus pygam / xgboost / lifelines for the chapters that need them — torch is preinstalled on Colab);

  2. loads each dataset from the ISLP package where possible, streams the four it does not ship (Advertising, Heart, Income1, Income2) from the book’s official site, and falls back to the bundled ALL CSV FILES - 2nd Edition/ folder otherwise.

So a fresh Colab runtime works with no manual downloads, and a local checkout works offline.

All notebooks

Where to go next

  • Lecture slides — the deck each lab accompanies.

  • For students — how the labs relate to the lectures, and what to do when your numbers differ.

  • Datasets — what is bundled, and which chapter uses it.

  • Python environment — the pinned packages, and the four chapter-specific ones.