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.torchChapter 10 (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.
lifelinesChapter 11 (survival analysis) — a self-study code reference, so you can skip the notebook if you only teach the 12-lecture plan. The package still installs, because
ISLPrequires it.
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 Lecture 1 onwards also installs the deep-learning stack you will not touch until Chapter 10:
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.
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.