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 |
|
||
0b · Precourse (b) — Toolkit |
|
||
1 · Introduction |
|
||
2 · Statistical Learning |
|
||
3 · Linear Regression |
|
||
4 · Classification |
|
||
5 · Resampling Methods |
|
||
6 · Model Selection & Regularization |
|
||
7 · Moving Beyond Linearity |
|
||
8 · Tree-Based Methods |
|
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:
detects whether it is running on Colab and installs any missing packages (
ISLP, pluspygam/xgboost/lifelinesfor the chapters that need them —torchis preinstalled on Colab);loads each dataset from the
ISLPpackage where possible, streams the four it does not ship (Advertising,Heart,Income1,Income2) from the book’s official site, and falls back to the bundledALL CSV FILES - 2nd Edition/folder otherwise.
So a fresh Colab runtime works with no manual downloads, and a local checkout works offline.
All notebooks¶
- Chapter 0 — Precourse Refresher
- Chapter 0b — Precourse Toolkit
- Chapter 1 — Introduction
- Chapter 2 — Statistical Learning
- Chapter 3 — Linear Regression
- Chapter 4 — Classification
- Chapter 5 — Resampling Methods
- Chapter 6 — Model Selection and Regularisation
- Chapter 7 — Moving Beyond Linearity
- Chapter 8 — Tree-Based Methods
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.