Python environment¶
requirements.txt pins the packages used by the notebooks and by the code
examples printed on the slides.
Purpose |
Packages |
|---|---|
Core scientific stack |
|
Statistics & machine learning |
|
Book companion (datasets + helpers) |
|
Chapter-specific |
|
Notebook environment |
|
Only xgboost is optional in practice. pygam, torch and lifelines are
pinned here for clarity, but they are also hard dependencies of ISLP and
arrive whether or not you list them — see
Why the install is large.
Install¶
Important
For a first session, don’t. Use Colab — it needs no install and runs every lab in the course. A local environment is the week-two route: better for real work, but not something to attempt with a room waiting.
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
Tested with Python 3.9+. Expect around 150 packages and several hundred megabytes — see Why the install is large below.
Notes on the chapter-specific packages¶
pygamUsed in the Chapter 7 lab for generalized additive models.
statsmodelscovers most of the chapter;pygamis what makes the smooth-term plots easy.xgboostOptional. Chapter 8 works end-to-end with scikit-learn’s
GradientBoostingClassifier;xgboostappears only in a side-by-side comparison.torchmodule A9 (deep learning). Preinstalled on Colab, so the Colab path needs no install; locally, install the build that matches your platform if you want GPU support. Note that it arrives whether you ask for it or not — see below.
lifelinesAdvanced module A6 (survival analysis, ISLP Chapter 11), which is self-study rather than taught. The Kaplan–Meier and Cox fits in that lab run on
lifelines, and it arrives withISLPin any case.
Why the install is large¶
There is no useful “minimal install” of this environment, and the reason is
ISLP itself. The book companion package does not merely suggest the
chapter-specific libraries — it hard-requires them. Its declared
dependencies include torch, pytorch_lightning, torchmetrics, lifelines
and pygam alongside the core scientific stack.
So asking for the datasets and helpers used from Chapter 1 onwards also installs the deep-learning stack you will not touch until module A9:
resolving
requirements.txtpulls in roughly 150 packages;on Windows that is several hundred megabytes of downloads,
torchalone over 100 MB;on Linux it is substantially more again — the
torchwheel bundles the CUDA libraries and is several hundred megabytes on its own.
Dropping torch>=2.1 from requirements.txt does not help: pip reinstates it
as a dependency of ISLP. The only genuinely light route is
Colab, where torch is already present.
Reproducing the stored numbers¶
Every notebook ships with its outputs, and those outputs are treated as a contract: the slides quote numbers the labs compute, so a lab that silently stops reproducing them desynchronises the course. Two files and one command keep that honest.
requirements.txt says what the labs need, deliberately loosely, so the course
keeps working as the ecosystem moves. constraints.txt records the one build
that was verified to produce the outputs currently stored in the notebooks — it
is a record, not a requirement. To reproduce the stored outputs exactly:
pip install -r requirements.txt -c constraints.txt
Then check the notebooks against themselves:
make notebooks # re-executes all 25 and diffs each cell against its stored output
The check reports two different failures and the distinction matters. An error means a cell raised — usually a missing package. Drift means the cell ran fine and printed something else, which is either a code change whose outputs were never refreshed or a dependency that changed the answer. The current state is 25 notebooks, 0 errors and 0 drift.
Two packages are pinned, and only two
Results proved insensitive to the rest of the stack — the Chapter 7 GAM reports
the same AIC across three years of numpy and scipy movement. The exceptions are
pinned in requirements.txt rather than merely recorded:
pygam==0.10.1— 0.12.0 changed the likelihood/AIC computation, moving Chapter 7’s reported AIC from 49773.69 to 30643.72. Python 3.9 resolvespygam>=0.9to 0.10.1 anyway, but 3.10+ (Colab included) picks up 0.12.0, so the stored numbers had quietly stopped matching there.ISLP==0.4.0— unpinned it spans 0.3.1 to 0.4.1, across whichload_data()does not return consistent dtypes.
A handful of stored outputs differ on every run and are not drift: the statsmodels and lifelines summaries print the current date, and pyGAM’s warning prefix names a kernel temp file whose path carries the process id. The checker normalises exactly those and nothing else, so it keeps catching the real changes it exists to catch.
Colab — the recommended route¶
Every notebook’s first cell detects Colab and installs only what’s missing, so you can open a lab in a fresh runtime and run it top to bottom — see Quick start. This is the day-one path for students, and it covers every lab in the course.
LaTeX¶
Rebuilding the slides or exams requires a TeX Live
distribution including beamer, tcolorbox, tikz, listings and booktabs.
Nothing else in the repository depends on LaTeX — the compiled PDFs are
committed.
Where to go next¶
Quick start — Colab in one click on day one, a local venv from week two.
For students — prerequisites, workload, and what to do when your numbers differ.
Lab notebooks — what the environment is for.
Building the docs — the separate, documentation-only requirements.
Lab notebooks — including which deck arithmetic each lab verifies in code.