Mathematical Prerequisites

Linear algebra, calculus, and matrix decompositions

Published

Last modified: 2026-10-22

Consolidated from Kameron Decker Harris’ 2022 weekly notes and Logan Sizemore’s Spring 2025 math review lecture.

This appendix fixes the notation the rest of the notes use and directs you to the worked calculations, interactive widgets, and exercises in the lab’s shared prerequisite site: Math for Data Science. The probability foundations are in Probability, and the statistical prerequisites are in Statistics.

Everything here is standard. Goodfellow et al. [1], chapter 2, covers linear algebra, and chapter 4 covers derivatives, gradients, and gradient-based optimization. Bishop [2] covers matrix identities in Appendix C, and Boyd and Vandenberghe [3] covers mathematical background in Appendix A.

Almost every model in these notes is built out of a handful of operations on vectors and matrices, together with the derivatives of functions that take those objects as input. Math for Data Science, the lab’s shared mathematics prerequisites, defines each of them with worked examples. This appendix links to those definitions rather than repeating them, and for the main ones says where these notes use them.

None of it is specific to machine learning. For a fuller treatment of the linear algebra, see chapter 2 of Goodfellow, Bengio and Courville [1].

1 Notation

Every model in this course takes numbers in and gives numbers out, and the numbers arrive as vectors (lists of numbers). One email is a vector of word counts; one patient is a vector of measurements. This chapter fixes the notation for those vectors, for the functions that map a vector to a number or to another vector, and for the derivative that tells us which direction to adjust a model.

Three conventions hold throughout the notes:

  • A single real number (a scalar) is written in plain italic: \(x\), \(w\), \(b\).
  • A column vector of \(\ninputvars\) real numbers, an \(\ninputvars \times 1\) array, is written with \vx (\(\vx \in \reals^{\ninputvars \times 1}\)) or \vec{x}. Vectors are columns unless something says otherwise.
  • A matrix — a rectangle of real numbers with \(m\) rows and \(n\) columns — is a capital letter: \(W \in \reals^{m \times n}\), or \(\mX\) for data matrices.

Scalars, vectors and matrices in these notes have real entries, with one exception: a covariate vector \(\vpredvar\) can mix numbers and categories, because a raw covariate may be categorical, such as a car’s country of origin. A feature function encodes it as numbers, which gives its feature vector, a column vector in \(\reals^{\ninputvars \times 1}\).

Other sources write \(\reals^{\ninputvars}\) for \(\reals^{\ninputvars \times 1}\), treat a vector as a row, or allow complex entries or categorical entries in a vector.

\(x_i\) is the \(i\)th entry of \(\vx\), and \(W_{ij}\) is the entry of \(W\) in row \(i\) and column \(j\). Row index first, always.

These notes use the shared mathematics macros from Morrison-Lab/macros, so their notation matches the notation chapters of Math for Data Science, Probability for Data Science, and Regression Models for Epidemiology. We write column vectors with \vx (\(\vx\)), which gives the same typography across all of the lab’s notes repositories.

Table 1: Notation used in this book
symbol meaning LaTeX
\(\vx \in \reals^{\ninputvars \times 1}\) column vector of \(\ninputvars\) real numbers \vx \in \reals^{\ninputvars \times 1}
\(\mX \in \reals^{\nobs \times \ninputvars}\) data matrix with \(\nobs\) observations and \(\ninputvars\) features \mX \in \reals^{\nobs \times \ninputvars}
\(\tp{x}\), \(\tp{\vx}\) transpose of a scalar or vector \tp{x}, \tp{\vx}
\(\dprod{\vx}{\vy}\) inner product of vectors \(\vx\) and \(\vy\) \dprod{\vx}{\vy}
\(\norm{\vx}_2\) Euclidean (\(\lpnorm{2}\)) norm / length of vector \(\vx\) \norm{\vx}_2
\(\Ep\), \(\Expf{\cdot}\) expectation of a random variable \Ep, \Expf{\cdot}
\(\Var{\cdot}\) variance of a random variable \Var{\cdot}
\(\odds\) odds \(\prob / (1 - \prob)\) of a probability \(\prob\) \odds
\(\logodds\) log-odds, the logarithm of the odds \(\odds\); also the linear component \(\lincomp\) of a logistic model \logodds
\(\ror\) odds ratio: the odds in one group divided by the odds in a reference group, written \(\ratio_{\odds}\) (the ratio symbol with the odds as subscript); \(\OR\) is its abbreviation in running text \ror, \OR
\(\eqdef\) defined as \eqdef
\(\indic{A}(x)\), \(\indicp{P}\) indicator function: \(1\) if condition holds, \(0\) otherwise \indic{A}(x), \indicp{P}
\(\ind\) independent \ind
\(\tf\) therefore, thus \tf, \therefore

For logical connectives, quantifiers, set notation, and proofs, see the Math for Data Science Notation page and Probability for Data Science Notation page.

1.1 Where different notation conventions come from

Machine learning, statistics, computer science, and econometrics developed their notations independently before converging on modern data science. Students reading across these literatures encounter different symbols for the same objects. Knowing where these conventions originate explains the choices:

  • Weights \(\vw, b\) vs. coefficients \(\vbeta, \beta_0\): In artificial intelligence and neural networks [1], [2], a linear function is written \(f(\vx) = \dprod{\vw}{\vx} + b\) (or \(W\vx + \vec{b}\)), where \(\vw\) contains synaptic weights and \(b\) is the bias shifting the activation threshold. In classical statistics and econometrics [4], [5], regression models trace back to Gauss and Legendre, using Greek letters (\(\vbeta\)) for unknown population parameters, and either Roman letters (\(\vec{b}\)) or a hat on the parameter (\(\hvb\)) for sample estimates. This chapter uses \(\vw\) and \(b\) after Goodfellow et al. [1], while Linear Regression and subsequent chapters use the traditional regression notation \(\vcoef\) and \(\beta_0\) (matching Regression Models for Epidemiology and Hastie et al. [4]). They represent the exact same mathematical linear model.

  • Dimension (\(D\) vs. \(p\)) and sample size (\(N\) vs. \(n\)): Computer science and machine learning texts typically denote the feature dimension by \(D\) (for dimension) or \(d\), with \(N\) data points [1], [2]. Statistical literature traditionally denotes the sample size by \(n\) and the number of predictors by \(p\) (for parameters or predictors) [4], [6].

  • Targets vs. responses: Neural networks and pattern recognition texts often denote the supervised label by a target \(t\) or \(y\) [2], [7], whereas statistics denotes the outcome as the response or dependent variable \(y\).

  • Rosetta stones across disciplines: Ripley [7, Sec. 1.1], Table 1.1 provides an early systematic glossary mapping parallel terminology between statistics and neural networks (inputs vs. predictors, outputs vs. responses, weights vs. coefficients, training vs. fitting). In economics, Varian [5] discusses the complementary perspectives and terminology of machine learning and econometrics (such as features vs. regressors and explanatory variables). Breiman [8] and Efron and Hastie [6] provide deeper historical perspective on how algorithmic modeling and data modeling traditions diverged and recombined.

Notation across sources sets our notation beside Brian Hutchinson’s and Kameron Decker Harris’ lecture notes and five widely used texts, one row per concept.

1.2 Vectors and inner products

Math for Data Science covers:

The inner product of two column vectors of the same length multiplies them entry by entry and adds up the results, so it takes two vectors in and returns a single number. Math for Data Science defines it, with a worked example, as the dot product. These notes write it as

\[\dprod{\va}{\vec{b}} = \sumto{i}{\ninputvars} a_i b_i \tag{1}\]

It is also called the dot product or the scalar product [9]. The three names are interchangeable. Which one you meet depends on whether the author came to the subject through linear algebra, through vector calculus, or through machine learning. These notes say inner product.

Almost every model in this course computes a score that way: a vector of weights, one per feature, and a vector of feature values, joined by their inner product.

A vector’s length, or \(\lpnorm{2}\) norm, is the square root of its inner product (Equation 1) with itself. Math for Data Science defines it as the Euclidean norm. These notes write it as

\[ \begin{aligned} \norm{ \va}_2 &= \sqrt{\dprod{\va}{\va}} \\ &= \sqrt{\sumto{i}{\ninputvars} a_i^2} \end{aligned} \tag{2}\]

It is also called a vector’s magnitude. The subscript 2 distinguishes it from the other \(\lpnorm{p}\) norms, and an unsubscripted \(\norm{ \va}\) almost always means this one.

In two dimensions that is the Pythagorean theorem, and in \(\ninputvars\) dimensions it is the same formula with more terms. Norms return when we penalize large weights in Linear Regression.

Math for Data Science provides a worked exercise:

VideosWatch
ReadingRead

GeeksforGeeks explains:

1.3 Matrices and the matrix product

Math for Data Science covers:

A matrix stores a whole dataset or a whole layer of a model.

Math for Data Science defines the matrix product \(AB\). The product exists only when the inner dimensions agree: \(A\) must be \(m \times n\) and \(B\) must be \(n \times p\), and the result is \(m \times p\). Entry \((i, j)\) of the product is the inner product (Equation 1) of row \(i\) of \(A\) with column \(j\) of \(B\) [14].

DefDefinition 1 (The shape rule)

Definition 1 (The shape rule) Write the two shapes side by side, and read off

\[(m \times n)(n \times p) \;\longrightarrow\; m \times p \tag{3}\]

The inner pair must match, and the outer pair is the answer’s shape.

ExmExample 1 (Checking the shapes in the normal equations)

Example 1 (Checking the shapes in the normal equations) Let \(\design\) be an \(n \times p^*\) design matrix and \(\vy \in \reals^{n \times 1}\) a response column vector. Use the shape rule on each product in \(\hvcoef = (\tp{\design}\design)^{-1}\tp{\design}\vy\):

  • \(\tp{\design}\design\) is \((p^* \times n)(n \times p^*)\). The inner pair \(n, n\) matches, so the product is \(p^* \times p^*\) and can be inverted.
  • \(\tp{\design}\vy\) is \((p^* \times n)(n \times 1)\). The inner pair matches, so the product is \(p^* \times 1\).
  • \((\tp{\design}\design)^{-1}\tp{\design}\vy\) is \((p^* \times p^*)(p^* \times 1)\), which is \(p^* \times 1\): one coefficient for each column of \(\design\), as it should be.

Reading the product in the other order fails the check. \(\design\design\) would be \((n \times p^*)(n \times p^*)\), and its inner pair \(p^*, n\) does not match unless \(n = p^*\), so the formula cannot be written that way.

The shape rule checks any expression in these notes quickly. If the shapes do not match, the expression is wrong, and we find that out without computing a single number.

Math for Data Science provides a worked exercise:

VideosWatch
ReadingRead

GeeksforGeeks explains matrix multiplication [16].

2 Linear functions

Every linear model in these notes is built out of linear and affine maps. Math for Data Science covers their definitions, geometry, and exercises:

VideosWatch
ReadingRead

GeeksforGeeks explains linear transformations [17].

Worked exercises in Math for Data Science:

3 Derivatives and gradients

Fitting a model means adjusting parameters until some measure of its error is small, guided by the gradient. The Gradient Descent chapter uses it. Math for Data Science covers calculus foundations and gradient checks:

Worked exercises in Math for Data Science:

VideosWatch
ReadingRead

GeeksforGeeks explains:

4 Decompositions

Math for Data Science covers:

Math for Data Science writes the SVD as \(\mathbf{U}\mathbf{D}\mathbf{V}^\top\). These notes write \(U S V^\top\) instead, because \(\ninputvars\) is the number of features throughout these notes. Both Math for Data Science and these notes write an eigendecomposition as \(Q \Eigvals Q^\top\) (or \(\mathbf{Q}\mathbf{\Eigvals}\mathbf{Q}^\top\)), where \(Q\) is the orthogonal matrix of eigenvectors [22].

VideosWatch

5 Further reading

  • Goodfellow et al. [1], Chapters 2 and 4, on linear algebra and optimization

  • Boyd and Vandenberghe [3], Appendix A

  • Starmer [27], on matrix algebra for neural networks

References

[1]
I. Goodfellow, Y. Bengio, and A. Courville, Deep learning. MIT Press, 2016. Available: https://www.deeplearningbook.org/
[2]
C. M. Bishop, Pattern recognition and machine learning. in Information science and statistics. New York: Springer, 2006.
[3]
S. Boyd and L. Vandenberghe, Convex optimization. Cambridge University Press, 2004. doi: 10.1017/CBO9780511804441.
[4]
T. Hastie, R. Tibshirani, and J. Friedman, The elements of statistical learning: Data mining, inference, and prediction, 2nd ed. Springer, 2009. Available: https://hastie.su.domains/ElemStatLearn/
[5]
H. R. Varian, “Big data: New tricks for econometrics,” Journal of Economic Perspectives, vol. 28, no. 2, pp. 3–28, 2014, doi: 10.1257/jep.28.2.3.
[6]
B. Efron and T. Hastie, Computer age statistical inference: Algorithms, evidence, and data science. Cambridge: Cambridge University Press, 2016. doi: 10.1017/CBO9781316576533.
[7]
B. D. Ripley, Pattern recognition and neural networks. Cambridge: Cambridge University Press, 1996. doi: 10.1017/CBO9780511812651.
[8]
L. Breiman, “Statistical modeling: The two cultures,” Statistical Science, vol. 16, no. 3, 2001, doi: 10.1214/ss/1009213726.
[9]
Wikipedia contributors, “Dot product — Wikipedia, the free encyclopedia.” 2026. Available: https://en.wikipedia.org/wiki/Dot_product
[10]
G. Sanderson, “Essence of linear algebra.” 3Blue1Brown, video series on YouTube, 2016. Available: https://www.youtube.com/playlist?list=PLZHQObOWTQDPD3MizzM2xVFitgF8hE_ab
[11]
B. Hutchinson, “DATA 471/571 (machine learning) and CSCI 481/581 (deep learning) video lectures.” Western Washington University. Accessed: Sep. 28, 2026. [Online]. Available: https://facultyweb.cs.wwu.edu/~hutchib2/video_lectures/data371/
[12]
GeeksforGeeks, “Dot product of two vector.” GeeksforGeeks, tutorial article, 2026. Available: https://www.geeksforgeeks.org/maths/dot-product/
[13]
GeeksforGeeks, “Vector norms.” GeeksforGeeks, tutorial article, 2026. Available: https://www.geeksforgeeks.org/maths/vector-norms/
[14]
Wikipedia contributors, “Matrix multiplication — Wikipedia, the free encyclopedia.” 2026. Available: https://en.wikipedia.org/wiki/Matrix_multiplication
[15]
J. Starmer, “Essential matrix algebra for neural networks, clearly explained.” StatQuest, video on YouTube, 2023. Available: https://www.youtube.com/watch?v=ZTt9gsGcdDo
[16]
GeeksforGeeks, “Multiplying matrices.” GeeksforGeeks, tutorial article, 2026. Available: https://www.geeksforgeeks.org/maths/multiplying-matrices/
[17]
GeeksforGeeks, “Linear transformation.” GeeksforGeeks, tutorial article, 2026. Available: https://www.geeksforgeeks.org/maths/linear-transformation/
[18]
Khan Academy, “Gradient 1: Partial derivatives, gradient, divergence, curl.” Video on YouTube, 2008. Available: https://www.youtube.com/watch?v=U7HQ_G_N6vo
[19]
J. Starmer, “The chain rule, clearly explained.” StatQuest, video on YouTube, 2020. Available: https://www.youtube.com/watch?v=wl1myxrtQHQ
[20]
GeeksforGeeks, “Partial derivative.” GeeksforGeeks, tutorial article, 2026. Available: https://www.geeksforgeeks.org/maths/partial-derivative/
[21]
GeeksforGeeks, “Gradient.” GeeksforGeeks, tutorial article, 2025. Available: https://www.geeksforgeeks.org/data-science/gradient/
[22]
Wikipedia contributors, “Eigendecomposition of a matrix — Wikipedia, the free encyclopedia.” 2026. Available: https://en.wikipedia.org/wiki/Eigendecomposition_of_a_matrix
[23]
S. L. Brunton, “Singular value decomposition (SVD).” Video series on YouTube, 2020. Available: https://www.youtube.com/watch?v=gXbThCXjZFM
[24]
A. Avati, “CS229: Machine learning, summer 2019.” Stanford Online, lecture videos on YouTube, 2019. Available: https://www.youtube.com/playlist?list=PLoROMvodv4rNH7qL6-efu_q2_bPuy0adh
[25]
GeeksforGeeks, “Eigenvalues and eigenvectors.” GeeksforGeeks, tutorial article, 2026. Available: https://www.geeksforgeeks.org/engineering-mathematics/eigen-values/
[26]
GeeksforGeeks, “Singular value decomposition (SVD).” GeeksforGeeks, tutorial article, 2025. Available: https://www.geeksforgeeks.org/data-science/singular-value-decomposition-svd/
[27]
J. Starmer, The StatQuest illustrated guide to neural networks and AI: With hands-on examples in PyTorch. Independently published, 2025. Available: https://statquest.org/statquest-store/
Back to top