Linear regression from the statistics view
Before this lesson: lesson 04 (covariance of a random vector, ), lesson 05 (the multivariate Gaussian), lesson 08 (maximum likelihood), lesson 10 (priors and posteriors) and lesson 11 (-tests and -values). From linear algebra: least squares with QR and projections. Time: about 80 minutes, plus the notebook.
Why this matters #
- Is the effect real? Every regression table in a paper or an experiment report shows coefficients, standard errors and -values. A/B tests are often analysed by regression, with covariates to reduce variance (CUPED in lesson 12).
- Uncertainty in predictions. A forecast needs an interval, and the right one is the prediction interval, not the confidence interval. Confusing them gives intervals that are far too narrow.
- Fits in ML research. Scaling laws are linear fits of log loss against log compute; the uncertainty of the fitted exponent decides how far you can extrapolate. Linear probes on network features are regressions too.
- Bayesian linear regression is the simplest Bayesian model with a closed-form posterior. It explains ridge and weight decay as a Gaussian prior, and it is the weight-space view of a Gaussian process (ml-for-science 07).
1. Predict first #
2. The picture #
The running example. Five students report hours of study and an exam score (out of 10):
| (hours) | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| (score) | 2 | 4 | 5 | 4 | 5 |
Least squares gives the line (section 4 does every step). So each extra hour is worth 0.6 points. But five students are few. Another class of five would give another line. How much would the slope change?
The model. We assume that the data come from a true line plus noise:
where the errors are i.i.d. . The are fixed (we condition on them). Only the noise is random. The fitted coefficients are functions of the noisy , so they are random variables. Their distribution over repeated data sets is the sampling distribution. You cannot see it from one data set, but you can simulate it:
Press "New data set" a few times, then "Add 100 data sets". The orange line is the true line. Each data set gives a fitted line: the newest is yellow, earlier ones are faint blue. The histograms collect and over all data sets; the orange curves are the theory from section 3. Make larger or smaller and watch the fan and the histograms get narrower.
The fan is narrow in the middle of the data and wide at the ends. The fitted lines all pass close to the point and rotate around it. A small change of slope moves the line a lot far from and very little near it. This one fact explains the shape of every band below.
Two questions, two bands. Take a new .
- Where is the mean response ? The only uncertainty is in the fitted line. This gives the confidence band.
- Where will one new observation fall? Now there are two sources: the uncertainty of the line, plus the new noise . This gives the wider prediction band.
Drag the yellow point along the line, then move the slider to the right. The orange band is the 95% confidence band for the mean; the violet band is the 95% prediction band for a new . Both are narrowest at . With large the orange band shrinks to the line, but the violet band stays about wide. A wider spread of makes the slope more precise (smaller SE, larger ).
Two designs have the same and the same noise . In design A the values are spread over ; in design B over (evenly spaced in both). How do the standard errors of the slope compare?
with . Spreading the same pattern 5 times wider multiplies every by 5, so by 25, so the SE is divided by 5. Points far from are not a problem: they are the ones that pin down the slope.
3. Definitions and main results #
The model and the least-squares estimator #
Write the data in matrix form. is the response, and is the design matrix: row holds the features of observation , and the first column is all ones (the intercept). In the exam example . The linear model is
We use these assumptions; each result says which ones it needs.
| Assumption | |
|---|---|
| A1 | linear mean: |
| A2 | is fixed and has full column rank (no column is a combination of the others) |
| A3 | errors have mean 0 and covariance : uncorrelated, with constant variance (homoscedastic) |
| A4 | errors are Gaussian: |
The ordinary least squares (OLS) estimator minimises the residual sum of squares . Setting the gradient to zero gives the normal equations , so
In code, never form the inverse: factor and solve (linear algebra 12). The fitted values are with the hat matrix . is the orthogonal projection onto the column space of . The residuals are . They are orthogonal to every column of : . With an intercept column this says .
OLS is the Gaussian maximum likelihood estimator. Under A4 the log-likelihood is . For any , maximising over means minimising . So the MLE of is (lesson 08). The MLE of is , which is biased; see below.
is a random vector #
Theorem (sampling distribution of OLS). Under A1–A3, and . Under A4 in addition,
Proof.
- Put into the formula. With (a fixed matrix): , because .
- Mean: .
- Covariance (lesson 04, ): .
- Under A4, is an affine function of the Gaussian vector , so it is Gaussian (lesson 05).
Simple regression. For one feature, . Inverting it gives
Three levers make the slope precise: less noise (small ), more points, and points spread far from (large ). If you repeat the same design times, grows by and the standard error shrinks by .
Estimating : why #
is unknown. The natural estimate uses the residuals:
Theorem. Under A1–A3, .
Why and not (intuition). The fitted line is chosen to be close to the data, so the residuals are smaller than the true errors. The residual vector is orthogonal to the columns of , so it lives in a space of dimension : fitting has used up directions. With points the fit is exact and all residuals are 0. The is called the residual degrees of freedom.
Proof: the trace of the hat matrix
- , so .
- is symmetric and idempotent (), so .
- For a random vector with mean 0 and covariance , (write and take the expectation). Here , so .
- (the trace is invariant under cyclic shifts).
- So and .
Under A4 one can say more: , and is independent of . Independence follows from lesson 05: and are jointly Gaussian, and because .
Standard errors, -tests and confidence intervals #
Replace by in the covariance. The standard error of coefficient is
Theorem. Under A1–A4,
Proof.
- by the theorem above.
- , independent of (end of the proof block above).
- (the unknown cancels). This ratio is the definition of Student's distribution (lesson 06).
This gives the usual tools (lesson 11):
- -test of : the -statistic is , and the two-sided -value is .
- Confidence interval at level 95%: , where is the 0.975 quantile. For large it is close to 1.96; for it is 3.18.
Confidence interval for the mean, prediction interval for a new #
Let be a new feature vector (with the leading 1). The prediction is . Let .
- Mean response . , so the 95% confidence interval is .
- New observation , with new noise independent of the data. The error is a sum of two independent terms, so . The 95% prediction interval is .
For simple regression : smallest at and growing quadratically away from it. That is the curved shape of the bands. As , : the confidence interval shrinks to a point, while the prediction interval tends to .
You fit a regression on points with noise . What is the approximate half-width of the 95% prediction interval for one new at ?
The half-width is with at . The term (uncertainty of the line) vanishes, but the 1 (the noise of the new observation) does not. is the half-width of the confidence interval for the mean.
, adjusted and the -test #
With an intercept, the total sum of squares splits into the explained part plus RSS (the cross term vanishes because is orthogonal to ). The coefficient of determination is
the fraction of the variance of that the model explains. In simple regression , the squared sample correlation of and . Adding a feature never increases RSS, so never goes down, even for a useless feature. The adjusted compares variance estimates instead, and can go down.
-test for nested models. A small model with columns is inside a big model with columns (the small model sets coefficients to 0). Under (the extra coefficients are 0) and A1–A4,
It asks: does the drop in RSS beat what noise alone would give? For one extra coefficient, and the two tests agree. The "overall -test" in regression output compares the model with the intercept-only model.
Significance is not size. In simple regression . With and : and . The slope is surely not 0, but explains only 2% of the variance of . A small -value says "there is an effect", not "the effect is large" or "the model predicts well".
You add a column of pure random noise to the design matrix and refit. What happens?
The bigger model can always set the new coefficient to 0, so its RSS is at most the old RSS and cannot drop. By chance the noise column fits a little of , so rises slightly. Adjusted divides RSS by , which got smaller, so it penalises the extra parameter.
The Gauss–Markov theorem #
Why least squares, and not another method? Call an estimator linear if it has the form for a fixed matrix , and unbiased if for every .
Theorem (Gauss–Markov). Under A1–A3 (no Gaussian assumption), OLS is the best linear unbiased estimator (BLUE): for every linear unbiased , the matrix is positive semidefinite. In particular, every coefficient and every combination has the smallest variance with OLS.
Proof
- Write with . Unbiasedness for every means for all , so . Since , this gives .
- .
- , and .
- So , and is positive semidefinite.
The theorem has limits. It compares only unbiased estimators: ridge regression is biased and can have a smaller mean squared error. It compares only linear ones: with heavy-tailed noise, a robust (nonlinear) fit can be much better. And it needs A3: with unequal variances, weighted least squares beats OLS.
Multicollinearity #
When two features are strongly correlated, the data cannot tell their effects apart. In the formula, is close to singular and is large. A clean way to say it: with an intercept,
where and is the of a regression of feature on all the other features. The factor is the variance inflation factor. For two features with correlation , : gives VIF 5.3 (standard errors 2.3 times larger), and gives VIF 50 (standard errors 7.1 times larger).
Move the correlation slider from 0 to 0.99. Each blue dot is from one data set with the same features and new noise; the orange ellipse is the 95% region of around the true . With correlated features the ellipse grows along the direction and tilts: the estimates are negatively correlated. The sum (the short axis) stays precise.
Multicollinearity does not bias , and it does not hurt predictions at values like the training data. It makes single coefficients unstable, so do not read much into their signs or sizes. It is the statistical face of a large condition number (linear algebra 13).
Diagnostics: when the assumptions fail #
All the formulas above trust A1–A4. Residual plots check them: plot against the fitted values (or against each feature, or against time). Under the model, this plot is a structureless band around 0.
| Assumption fails | What the residual plot shows | What goes wrong | Common fix |
|---|---|---|---|
| A1: the truth is curved | a U shape or a wave | is biased; predictions are wrong | add features (, splines), transform or |
| A3: variance not constant (heteroscedastic) | a fan: spread grows with | is still unbiased, but the classical SEs are wrong (often too small) | robust standard errors; weighted least squares; |
| A3: errors correlated (time series, groups) | waves in against time; clusters | SEs too small: the data carry less information than suggests | cluster or HAC standard errors; the block bootstrap (lesson 12) |
| A4: errors not Gaussian | skew or heavy tails (check a Q–Q plot) | exact and tests fail for small ; for large the CLT rescues them | larger , the bootstrap, a robust fit |
| one point dominates | may show nothing (see below) | the fit follows one point | check leverage and influence |
Leverage. The diagonal entries of the hat matrix are the leverages: , so measures how much pulls its own fitted value. They lie in and add up to , so the average is ; a common flag is . In simple regression : points with an extreme have high leverage. A high-leverage point pulls the line toward itself, so its own residual is small, and the residual plot can hide it. Measures of influence such as Cook's distance combine leverage and the residual.
Try the four presets. Blue points are data, the orange line is the least-squares fit, and magenta points have high leverage (). The right plot shows residuals against fitted values. Compare the classical and the robust standard error of the slope in each case: they agree for the good model and differ when the noise grows with .
Heteroscedasticity-robust (sandwich) standard errors
If is diagonal but not , step 3 of the proof above gives . The two outer factors are the "bread" and the middle is the "meat". White (1980) showed that you can replace by (the HC0 estimator) and get a consistent estimate of the covariance, even though each is a poor estimate of its own variance. The average over terms does the work. In small samples HC0 is too small; the HC3 variant uses and is the usual default. Cluster-robust and HAC (Newey–West) estimators extend the same sandwich to correlated errors.
Correlation is not causation. A coefficient measures how changes with when the other included features are held fixed. If a variable that affects both and is left out (a confounder), absorbs its effect. If the true model is and you fit on alone, then , where is the slope of on (the omitted-variable bias). Small standard errors do not fix this; see causal inference 01.
Bayesian linear regression #
The Bayesian view (lesson 10) treats itself as random. Keep the Gaussian likelihood with a known noise variance , and put a Gaussian prior on the coefficients:
where is the prior precision (a large says "the coefficients are small").
Theorem (Bayesian linear regression). The posterior is with
and the posterior predictive distribution of a new at is .
Proof.
- Bayes: .
- Expand and collect the terms in : .
- The log-density of is . Matching the quadratic terms gives ; matching the linear terms gives .
- Predictive: , with and independent . The sum is Gaussian with mean and variance .
The posterior mean is ridge regression. Multiply inside and outside the inverse by :
the minimiser of with . The posterior is Gaussian, so is also the MAP estimate. Weight decay in a neural network is the same idea: a Gaussian prior on the weights.
Two limits. With a flat prior (), (OLS) and : the same matrix as the frequentist . With known the 95% credible interval and the 95% confidence interval are then numerically equal, although they answer different questions. With much data, shrinks like and the predictive variance tends to the noise , just like the prediction interval.
Click in the plot to add data points; then move the prior precision . Blue points are data. In aqua: the posterior mean line (thick), 12 lines sampled from the posterior (thin), and the 95% predictive band. The dashed grey line is least squares. "Clear points" shows the prior. A large pulls the line toward 0 (strong ridge); a small makes the mean line match least squares. Far from the data the band widens.
The function-space view: a Gaussian process with a linear kernel
Under the prior, is jointly Gaussian with and . Gaussian conditioning (lesson 05) gives . The push-through identity shows that the two forms agree. The second form only needs inner products : this is a Gaussian process with the linear kernel . Replace the features by , or the kernel by any positive definite kernel, and you get GP regression (ml-for-science 07). The weight-space form solves a system; the function-space form an one.
If is unknown too, a normal–inverse-gamma prior on is conjugate. The predictive distribution is then a Student , the Bayesian counterpart of the above.
In Bayesian linear regression with prior and noise variance , the posterior mean equals ridge regression with which penalty ?
Multiply by : . The penalty is the prior precision times the noise variance. is a common slip that is right only when .
Answers to section 1. (1) points with the same design make four times larger, so the standard error is divided by . (2) Close to a fixed width: about (the noise of the new point does not shrink). (3) Yes. With , gives and ; with larger the -value is even smaller.
4. Worked example #
Back to the five students. Every number below is checked in section 5.
Step 1: the matrices. With the intercept column,
Step 2: the coefficients. , so
Step 3: residuals. Fitted values , so . Check: and (the residuals are orthogonal to both columns). .
Step 4: noise variance and standard errors. , so . The estimated covariance is
so and . (Check with the simple formula: and .)
Step 5: test and interval for the slope. with 3 degrees of freedom; the two-sided -value is . With , the 95% confidence interval is . It contains 0: five students are not enough to show that studying helps, even though the estimate is positive.
Step 6: and . , so and . Adjusted . The overall , with the same .
Step 7: the two intervals at a new . and .
| SE of the mean | 95% CI for the mean | SE for a new : | 95% prediction interval | |||
|---|---|---|---|---|---|---|
| 3 | 4.0 | 0.2 | 0.40 | 0.98 | ||
| 6 | 5.8 | 1.1 | 0.94 | 1.30 |
At we extrapolate outside the data, and the confidence interval is more than twice as wide as at . The prediction interval is wide in both places, because one student's score is noisy.
Step 8: the Bayesian version. Take one feature without intercept, prior precision , noise variance , data , . Then and .
- and .
- Ridge with : . Least squares gives : the prior shrinks the slope toward 0.
- Predictive at : mean , variance . At : , of which only is uncertainty about the slope. At : , of which 94% is uncertainty about the slope.
In the exam example, a sixth student studies hours. Which interval should you report for this student's score, and roughly how wide is it?
The confidence interval covers the average score of all students who study 3 hours. One student also has their own noise, so the variance is , not . The last option ignores both the uncertainty of the line and the quantile for 3 degrees of freedom.
5. In code #
NumPy and SciPy check the worked example. scipy.stats.linregress is the 1-D cross-check.
import numpy as np
from scipy import stats
x = np.array([1., 2, 3, 4, 5]) # hours of study
y = np.array([2., 4, 5, 4, 5]) # exam score
X = np.column_stack([np.ones_like(x), x]) # intercept column + x
n, p = X.shape
Q, R = np.linalg.qr(X) # least squares through QR, no inverse of X^T X
beta = np.linalg.solve(R, Q.T @ y)
e = y - X @ beta
s2 = e @ e / (n - p) # unbiased estimate of sigma^2
XtX_inv = np.linalg.inv(R.T @ R) # small p: fine for the standard errors
se = np.sqrt(s2 * np.diag(XtX_inv))
t = beta / se
pval = 2 * stats.t.sf(np.abs(t), df=n - p)
tq = stats.t.ppf(0.975, df=n - p)
print(beta.round(3), round(e @ e, 3), round(s2, 3)) # [2.2 0.6] 2.4 0.8
print(se.round(3), t.round(3), pval.round(3)) # [0.938 0.283] [2.345 2.121] [0.101 0.124]
print((beta[1] - tq * se[1]).round(2), (beta[1] + tq * se[1]).round(2)) # -0.3 1.5
R2 = 1 - e @ e / np.sum((y - y.mean())**2)
lr = stats.linregress(x, y) # the 1-D check
print(round(R2, 3), round(lr.slope, 3), round(lr.stderr, 3), round(lr.pvalue, 3)) # 0.6 0.6 0.283 0.124
for x0 in (3.0, 6.0): # half-widths: CI for the mean, prediction interval
v = np.array([1, x0]) @ XtX_inv @ np.array([1, x0])
print(x0, round(beta[0] + beta[1] * x0, 2), (tq * np.sqrt(s2 * v)).round(2), (tq * np.sqrt(s2 * (1 + v))).round(2))
# 3.0 4.0 1.27 3.12
# 6.0 5.8 2.99 4.12
# Bayesian linear regression = ridge with lambda = alpha * sigma^2
alpha, sigma2 = 1.0, 0.8
S_N = np.linalg.inv(alpha * np.eye(p) + X.T @ X / sigma2)
m_N = S_N @ X.T @ y / sigma2
ridge = np.linalg.solve(X.T @ X + alpha * sigma2 * np.eye(p), X.T @ y)
print(m_N.round(3), np.allclose(m_N, ridge)) # [1.277 0.839] True
The last line has a lesson of its own: this prior shrinks the intercept toward 0 too, and the slope grows to compensate. In practice one usually centres and the features, or leaves the intercept without a prior.
6. Where it shows up #
- Experiments and A/B tests. The treatment effect is the coefficient of a 0/1 treatment feature; adding pre-experiment covariates is regression adjustment (CUPED), which shrinks the standard error by about (lesson 12). A two-sample -test is exactly a regression on a group indicator.
- Scaling laws and empirical fits in ML. A power law is a line in log–log coordinates. The standard error of the slope and the prediction interval tell you how far the fit can be trusted, and extrapolation is the case far from , where both bands are widest.
- Linear probes and attribution. Regressing a property on network activations is linear regression; with thousands of correlated features, multicollinearity makes single coefficients meaningless, so people use ridge.
- Bayesian last layers and uncertainty. Bayesian linear regression on learned features gives cheap predictive uncertainty; with random Fourier features it approximates a Gaussian process. Thompson sampling with a linear model samples from (reinforcement learning 03).
- Trends in science. A warming trend in temperature data is a regression slope. The residuals of climate and weather series are autocorrelated, so the classical standard error is too small and the trend looks more significant than it is; corrected (HAC) standard errors or an effective sample size are needed.
- Calibration of instruments. Fitting a sensor's response against known standards, then predicting the unknown quantity with an interval, is a textbook use of the prediction interval.
7. Common mistakes #
- Using the confidence interval for a single prediction. It covers the mean response only. A new observation needs the prediction interval, which includes .
- Dividing RSS by . That is the MLE and it is biased low; use , especially when is not small compared with .
- Reading a small -value as a large effect. With large , tiny effects are significant. Report the estimate and its confidence interval, and look at or the size of the effect.
- Trusting classical standard errors without looking at the residuals. Curvature biases the coefficients; heteroscedasticity and correlated errors make the standard errors wrong. Plot the residuals first.
- Interpreting single coefficients under strong collinearity. Their signs can flip between similar data sets. Look at the VIF, or at combinations that are well determined.
- Reading a coefficient as a causal effect. It is an association given the included features. Omitted confounders bias it, whatever the standard error.
- Comparing across models with different numbers of features. always rises when features are added; use adjusted , an -test or held-out error.
- Forming to fit the model. Solve with QR (or
np.linalg.lstsq); the explicit inverse squares the condition number.
8. Check yourself #
- Under A1–A3, show that the fitted values satisfy and the residuals
. What does this say about the variance of a residual with high leverage?
Answer
, so ( is symmetric and idempotent). , so and . A point with leverage close to 1 has a residual with variance close to 0: the line goes through it. This is why studentised residuals divide by . - A regression on points with columns has . Estimate . A coefficient has
and . Is it significant at the 5% level?
Answer
, so . , with 26 degrees of freedom. , so no (). - Why is the prediction band of simple regression curved (a hyperbola), and not two parallel lines?
Answer
The variance of the fitted line at is : the uncertain slope moves the line more the farther you are from . The half-width is the square root of a quadratic in , which is a hyperbola. Only the noise term is the same everywhere. - You fit on and with correlation . Both -statistics are about 1, but the overall -test has
. Explain.
Answer
Each -test asks whether one coefficient is 0 *given* the other feature. With correlated features either one alone explains , so neither adds much given the other, and their SEs are inflated (VIF ). The -test asks whether both are 0, and together they clearly explain . The sum of the coefficients is well determined; the split between them is not. - In Bayesian linear regression, what happens to and when ? And when the data set grows?
Answer
: and ; the prior wins and the data are ignored. As grows (with well-spread ), grows like , so like and the OLS estimate: the data win. The predictive variance tends to . - Why does stay unbiased under heteroscedastic errors, while its standard error does not?
Answer
Unbiasedness uses only : . The covariance uses ; with it becomes , which the formula does not estimate. The sandwich estimator does.
Write the OLS estimator and its covariance under .
, with (and ).
What is the variance of the slope in simple regression?
with .
Why does the unbiased noise estimate divide RSS by ?
: the residuals live in an -dimensional space because fitting uses directions.
What is the -statistic for , and its null distribution?
with ; under Gaussian errors it follows .
How do the confidence interval for the mean and the prediction interval for a new at differ?
Mean: ; new : , with . The extra 1 is the noise of the new observation.
Define .
, the fraction of the variance of explained by the model; in simple regression it is the squared correlation.
State the Gauss–Markov theorem in one sentence.
Under uncorrelated, equal-variance, mean-zero errors, OLS has the smallest covariance among all linear unbiased estimators (it is BLUE).
Which ridge penalty gives the posterior mean of Bayesian linear regression with prior ?
: .
What is the predictive variance of Bayesian linear regression at ?
: the noise plus the uncertainty of the coefficients.
Two features have correlation 0.99. By how much are the standard errors of their coefficients inflated?
VIF , so the standard errors grow by .
9. Interview angle #
- "What are the assumptions of linear regression, and which ones matter for what?" — Linear mean (else biased coefficients); uncorrelated, constant-variance errors (else wrong standard errors, though stays unbiased); Gaussian errors (only for exact small-sample and tests); full-rank (else is not unique). Check them with residual plots.
- "Derive the variance of ." — , and .
- "Confidence interval vs prediction interval?" — Mean response vs one new observation; the second adds and does not shrink to zero.
- "Your coefficient has but . What do you tell the product team?" — There is very likely an association, but explains about 1% of the variation of ; report the effect size with its interval, and do not claim the model predicts well. Check for confounders before claiming a causal effect.
- "What is multicollinearity and how do you detect it?" — Correlated features inflate the variance of single coefficients (); predictions are fine. Detect with VIFs or the condition number of ; fix with ridge, by combining features, or by dropping one.
- "Derive ridge regression from a Bayesian model." — Gaussian likelihood and prior ; the negative log-posterior is , whose minimiser is ridge with .
- "Why is OLS called BLUE?" — Gauss–Markov; also say what it does not claim (biased estimators like ridge can have lower MSE).
10. Practice #
The notebook for this lesson has five exercises, each with a check cell and a folded solution:
ols_table: coefficients, standard errors, -values and -values from scratch, checked againstscipy.stats.linregressand against a simulation of the coefficient spread.- Coverage of the 95% confidence interval for the slope by simulation, with Gaussian and with heteroscedastic errors (classical and robust standard errors).
- Coverage of the confidence interval for the mean and of the prediction interval for a new observation.
blr_posteriorandblr_predictive, with the check that equalssklearn.linear_model.Ridge(alpha=α·σ², fit_intercept=False).- The diabetes data set (
sklearn.datasets.load_diabetes): a coefficient table, VIFs and a residual plot.
11. Watch and read #
- Gareth James, Daniela Witten, Trevor Hastie and Robert Tibshirani, An Introduction to Statistical Learning, 2nd edition (free PDF): chapter 3 (standard errors, -tests, , the -test, residual plots, outliers, leverage and collinearity).
- Christopher Bishop, Pattern Recognition and Machine Learning (free PDF): §3.1 (least squares as maximum likelihood) and §3.3 (Bayesian linear regression and the predictive distribution).
- Kevin Murphy, Probabilistic Machine Learning: An Introduction (free PDF): §11.2 (least squares and its sampling distribution) and §11.7 (Bayesian linear regression).
- Cosma Shalizi, The Truth About Linear Regression (free lecture notes): what each assumption buys, and what to do when it fails.
Runs in your browser with nothing to install. The notebook repeats the key demos and has exercises with checks; solutions are inside, folded.
No Google account needed: Python runs inside your browser. The first start downloads about 40 MB; your changes are saved in this browser only.