◢◤ ARKANE_
SYS_TIME UTC+0
Work with me

Chapter 3 quiz · 26 questions

Maths Foundations: Statistics, Probability & Linear Algebra

Tests whether you can apply the chapter's maths by hand. Bayes posteriors, distribution probabilities, z-scores, correlation, t-statistics and effect sizes, matrix products and inverses, and the normal equations on tiny datasets.

Based on chapter 3. Every answer comes with an explanation and a link back to the section.

/Q3

Quiz

Question 1 of 26

Conditional probability, Bayes' theorem and base rates Level 1
Progress

In Bayes' theorem, P(A∣B)=P(B∣A) P(A)P(B)P(A \mid B) = \dfrac{P(B \mid A)\,P(A)}{P(B)}, with AA the label and BB the observed features. Which term is the likelihood?

Choose one
/02

练习From the book

8 exercises

The chapter's own exercises are open questions. Try one, then compare with the model answer.

Exercise 3.1 [W]

Using the disease-test numbers from Listing 3.6, explain in your own words why P(disease∣positive)P(\text{disease} \mid \text{positive}) comes out so much lower than the test's 99% sensitivity would naively suggest.

Show the model answer

The 99% sensitivity figure describes P(positive∣disease)P(\text{positive} \mid \text{disease}), not P(disease∣positive)P(\text{disease} \mid \text{positive}). Those two conditional probabilities are not the same quantity, despite sounding similar. Bayes' theorem forces the base rate into the calculation. The disease is rare (1% prevalence), so the pool of healthy people is roughly 99 times larger than the pool of diseased people. Even a modest 5% false-positive rate among that huge healthy majority produces far more false positives in absolute terms than the true positives produced by the small diseased minority testing correctly. The 99% figure describes the test's behaviour conditioned on already knowing someone is sick. It says nothing about what to conclude before knowing that. That's exactly the direction the diagnosis question runs.

Exercise 3.2 [W]

For each of the following, name the distribution (Gaussian, Bernoulli, Binomial, or Poisson) that best describes it, and justify your choice in one sentence: (a) whether a single email is spam; (b) the number of fraudulent transactions in a given hour; (c) the number of heads in 50 coin flips; (d) the measurement error of a sensor reading a stable physical quantity.

Show the model answer

(a) Bernoulli: a single binary outcome (spam or not) with no notion of counting across trials. (b) Poisson: counting rare, independent events (fraud) within a fixed interval (an hour), governed by a rate. (c) Binomial: the sum of 50 independent Bernoulli trials (each flip), counting successes. (d) Gaussian: measurement error from many small, independent sources of noise summing together is the textbook Central Limit Theorem scenario.

Exercise 3.3 [A]

Using Procedure 3.1 and the iris dataset, compute the correlation between sepal width (cm) and every other feature. Which pair has the weakest (closest to zero) correlation, and does that match the intuition that sepal width is the "odd one out" of the four iris measurements?

Show the model answer

Computing df.corr() restricted to sepal width (cm) against the other three iris features gives: petal length (cm) r≈−0.428r \approx -0.428, petal width (cm) r≈−0.366r \approx -0.366, and sepal length (cm) r≈−0.118r \approx -0.118. The weakest (closest to zero) is sepal length (cm) at r≈−0.118r \approx -0.118, negligible by the Correlation Interpretation Guide. This does match the intuition that sepal width is the odd one out. The other three iris measurements are strongly inter-correlated (petal length and petal width alone correlate at r=0.963r=0.963), while sepal width barely tracks any of them, including the other sepal measurement.

Exercise 3.4 [A]

Extend Listing 3.7 to use two features, petal length (cm) and sepal length (cm), to predict petal width (cm). You only need to change how X_raw is constructed. The normal-equations solve is unchanged. Report the new R2R^2 and state whether adding the second feature meaningfully improved the fit over the single-feature model.

Show the model answer

Extending Listing 3.7 to X_raw = df[['petal length (cm)', 'sepal length (cm)']].values and solving gives weights w ~ [-0.0090, 0.4494, -0.0822] (intercept, petal-length coefficient, sepal-length coefficient) and R2≈0.9290R^2 \approx 0.9290. That compares to R2≈0.9271R^2 \approx 0.9271 for the single-feature model. The improvement is real but tiny, about 0.002 of additional variance explained. The new coefficient on sepal length (cm) is small and negative, suggesting it's picking up a small amount of residual signal (likely correlated with, rather than independent of, petal length) rather than contributing meaningful new information. Adding the second feature does not meaningfully improve the fit.

Exercise 3.5 [A]

Using Listing 3.4, run a two-sample t-test comparing petal length (cm) between setosa and versicolor in the iris dataset. Report the p-value and Cohen's dd, and state in one sentence whether the difference is both statistically significant and practically large.

Show the model answer

Running Procedure 3.4 on petal length (cm) for setosa vs. versicolor gives t≈−39.49t \approx -39.49, p≈5.4×10−62p \approx 5.4 \times 10^{-62}, and Cohen's d≈−7.90d \approx -7.90. The difference is both statistically significant (the p-value is astronomically below any conventional threshold) and practically enormous. A Cohen's dd near 8 is far beyond the "large" cutoff of 0.8. These two species' petal lengths barely overlap at all.

Exercise 3.6 [E]

A colleague reports "we found a statistically significant improvement, p=0.002p = 0.002" as the sole justification for shipping a model change. Using this chapter's discussion of p-values and effect sizes, write the two or three follow-up questions you'd ask before agreeing the change should ship.

Show the model answer

Before agreeing to ship on "p=0.002p = 0.002" alone: (1) What is the effect size, and is it large enough to matter for the business metric it's supposed to move? A real but tiny lift can hit p=0.002p=0.002 purely from a large sample size, exactly as the chapter's 0.9000→0.9001 accuracy example illustrates. (2) What is the confidence interval around the effect, and does its lower bound still represent a meaningful improvement, or does it include effect sizes too small to justify shipping? (3) How many other comparisons were run before this one was reported? Was this the only test, or one of several? If several, an uncorrected p-value overstates the evidence (multiple-comparisons / p-hacking risk).

Exercise 3.7 [E]

Section "Linear Algebra" argues that feature scaling matters because dot products and distance metrics are sensitive to raw magnitude. Construct a small numeric example (two features, three or four data points) where an unscaled Euclidean distance calculation is dominated by one feature, and show the same calculation after standardising both features to mean 0 and standard deviation 1.

Show the model answer

Take two features, income (values like 30000, 60000, 90000) and age (values like 25, 45, 65), across three data points: P1=(30000,25)P_1=(30000, 25), P2=(60000,45)P_2=(60000, 45), P3=(90000,65)P_3=(90000, 65). The unscaled Euclidean distance between P1P_1 and P2P_2 is (30000)2+(20)2≈30000.007\sqrt{(30000)^2 + (20)^2} \approx 30000.007. income alone accounts for essentially the entire distance. age's contribution is invisible to four significant figures. After standardising both features to mean 0 and standard deviation 1 (via (x - mean) / std, with the population std (ddof=0) across the three points, as StandardScaler uses; pandas' default .std() uses ddof=1 and gives ±1\pm 1 and a distance of 1.41 instead), each feature's z-scores follow the same pattern: roughly −1.22,0,1.22-1.22, 0, 1.22 for both, since both are evenly spaced 3-point sequences. The scaled Euclidean distance between P1P_1 and P2P_2 becomes (1.22)2+(1.22)2≈1.73\sqrt{(1.22)^2 + (1.22)^2} \approx 1.73, with income and age now contributing equally. The raw-scale calculation was entirely dominated by the feature with the larger numeric range, even though nothing about the problem says income should matter 1500x more than age.

Exercise 3.8 [R]

Read Murphy's Appendix B on linear algebra [@murphy2022pmlintro]. Find one operation or concept covered there that this chapter didn't mention, and explain in a short paragraph where it would become relevant later in this book (for instance, in the PCA or neural network chapters).

Show the model answer

Discussion only. No single answer. Candidates worth pursuing: Singular Value Decomposition (A=UΣV⊤A = U\Sigma V^\top) appears only in Appendix A's Quick Reference. The chapter itself never discusses it. It underlies PCA's actual numerical implementation: sklearn.decomposition.PCA uses SVD rather than eigendecomposing the covariance matrix directly, for numerical stability. It reappears in Chapter 15's dimensionality reduction. Alternatively, positive-definiteness and matrix rank: Murphy's Appendix B covers when X⊤XX^\top X is guaranteed invertible. That connects directly back to this chapter's warning that the normal equations fail under collinear features, and explains why that failure happens, rather than just stating that it does.

online /books/classical-data-science/quiz/3 Newcastle, UK v0.1.0 // rss