Why Machine Learning Needs Mathematics: Rewriting Learning as Loss Minimisation
Prerequisite:Vector Spaces and Linear Maps: From the Eight Axioms to the Rank-Nullity Theorem、Limits and Continuity: Reading ε-δ as a Contract on Error、Probability Spaces and Kolmogorov's Axioms: Probability as a Measure of Total Mass One
0. Key points
Section titled “0. Key points”- Supervised learning, once the data, the hypothesis class and the loss function have been fixed, can be rewritten as a single optimisation problem: find the parameters that minimise the empirical risk. Regression and classification both fit inside this frame.
- Arranging the data into a design matrix and a target vector turns the minimisation of the squared loss into the normal equation , and geometrically into the orthogonal projection of onto the column space (Theorem 3.2). This is the role of linear algebra.
- The tool that carries out the minimisation is differentiation. For a convex function, “the gradient vanishes” and “the point is a global minimiser” are equivalent (Theorem 4.2), and both the range of learning rates for which gradient descent converges and the optimal learning rate are determined solely by the eigenvalues of (Theorem 4.4).
- Probability answers the question “why the squared loss?”. Maximum likelihood estimation under Gaussian noise coincides exactly with least squares (Theorem 5.2), while assuming a Bernoulli distribution produces the cross-entropy (Example 5.3).
- Probability also explains why we may use the error measured on our finitely many samples in place of the error on unseen data (Proposition 5.4). This guarantee, however, breaks the moment the model is chosen after looking at the data. That is what overfitting really is.
1. Motivation: what a single line of a learning library hides
Section titled “1. Motivation: what a single line of a learning library hides”With a machine learning library, training a model takes one line. Hand over the data, call the fitting method, and a few seconds later you can make predictions. Seen from here, mathematics appears to have no part to play.
The trouble starts when that one line does not work. For instance, the following things happen.
- Changing the learning rate from to makes the loss diverge instead of decrease.
- Changing the units of a feature from centimetres to metres cuts the number of iterations needed for convergence by a factor of several dozen.
- The error on the training data is almost zero, yet the model is hopeless on new data.
- Regression uses the squared error, while classification uses a different quantity called the cross-entropy.
Trial and error against these problems has no end, but rewritten in mathematical language each of them is explained in a single short sentence. In the second half of this article we answer all four.
Looking back at the history, the problem of “fitting a model to data” is some two hundred years older than machine learning. Legendre published the method of least squares in 1805, as an appendix to a work on determining the orbits of comets. In his Theoria Motus Corporum Coelestium of 1809, Gauss showed that if observation errors are assumed to follow a normal distribution, then least squares yields the most likely estimate. The idea of deriving the loss function from a probabilistic model, still used verbatim in modern deep learning, was already present at that point.
This article has two goals. First, to formulate regression and classification, two apparently separate tasks, as one and the same optimisation problem, the minimisation of the empirical risk. Second, to see where and why linear algebra, calculus and probability each become necessary in solving that problem, by carrying a single example, linear regression, all the way through the computation.
2. Formulating the learning problem
Section titled “2. Formulating the learning problem”We first fix the vocabulary. From now on vectors are written in bold, , and matrices as ; the standard inner product on is and the associated norm is .
Definition 2.1(The supervised learning setup)
Let be an input space and an output space, both sets, and fix a probability distribution on . The samples
drawn independently from , all with the same distribution, are called the training data. Fix a space of predicted values; a map is called a predictor, and a set of predictors fixed in advance is called a hypothesis class. Finally, a function is called a loss function, and expresses the penalty for predicting when the correct answer is .
The case is called regression, and the case where is a finite set is called classification.
The reason for introducing a space of predicted values separate from is classification. Even in binary classification, where the labels are , what the model outputs is normally the probability that the label is , that is, a value in . This distinction earns its keep in Example 5.3.
Definition 2.2(Expected risk and empirical risk)
In the setting of Definition 2.1, for a predictor put
These are called the expected risk (generalisation error) and the empirical risk (training error) of . The learning principle of selecting the predictor that minimises over is called empirical risk minimisation.
The relation between these two quantities generates very nearly all of the difficulty in machine learning. What we truly want to make small is , but the distribution is unknown, so cannot be computed. All we can compute is , measured on the data at hand. How far this substitution is justified is treated in Proposition 5.4.
Once the hypothesis class is described by finitely many parameters, learning becomes a finite-dimensional optimisation problem. Parametrising and setting
learning is nothing other than the problem “find a minimiser of the function on ”. The overall flow is as follows.
flowchart TD A["1. Data: collect n pairs of input and correct answer"] --> B["2. Representation: arrange them into a design matrix X and target vector y — linear algebra"] B --> C["3. Hypothesis class: set up predictors f_w indexed by a parameter w"] C --> D["4. Loss: quantify the misfit as the empirical risk L(w) — probability and statistics"] D --> E["5. Optimisation: move w in a direction that decreases L — calculus"] E --> F["6. Evaluation: estimate the error R on unseen data — probability and statistics"] F --> C
We now look at stages 2, 5 and 6 in turn. The subject matter is the simplest possible one, linear regression, and yet all three areas of mathematics show their faces there.
3. Linear algebra: arranging the data into a matrix
Section titled “3. Linear algebra: arranging the data into a matrix”Take the inputs to be points of , that is, tuples of real-valued features. Stacking the inputs vertically gives the matrix
called the design matrix and the target vector. Rows correspond to data points and columns to features. When an intercept (bias) is needed, taking the first feature to be the constant absorbs it into , so below we give the intercept no special treatment.
Taking the linear model , all predictions are written together as a single matrix-vector product . This is the first benefit of linear algebra as a language of representation. A loop over individual data points is replaced by one matrix operation, which not only shortens the description but also lets an implementation hand the work over to highly optimised matrix-product routines or to a GPU.
With the loss (the factor is merely a convenience so that the disappears on differentiation), the empirical risk becomes
Finding a minimiser of this function is linear regression. The key is the following completely elementary identity.
Lemma 3.1(Quadratic expansion of the squared loss)
Let and , and put . For all ,
In particular is totally differentiable on , with gradient .
Proof(Lemma 3.1)
Put , so that . Bilinearity and symmetry of the inner product give
Applying the defining property of the transpose, , to the second term and dividing throughout by yields the stated identity.
We check differentiability. The second term is a linear form in . The third term is bounded, by the Cauchy–Schwarz inequality(Theorem 4.2)[内積空間とグラム・シュミット直交化], as
and is a constant independent of , so that as . Hence, by the very definition of total differentiability, is differentiable and its gradient is the coefficient vector of the linear form, namely .
Theorem 3.2(The normal equation)
Let and , and put . A point is a global minimiser of if and only if
This equation is called the normal equation.
Proof(Theorem 3.2)
Put . Applying Lemma 3.1 with , we obtain, for every ,
(Sufficiency.) If , the first term on the right vanishes and the remaining is nonnegative. Hence for every , that is, is a global minimiser.
(Necessity.) Suppose is a global minimiser. Fix arbitrarily and replace by () in the identity above; minimality gives
for every . Multiply both sides by . For , dividing by gives , and letting yields . For , dividing by reverses the inequality, giving , and letting yields . Combining the two, . Since was arbitrary, taking gives , that is, .
The normal equation compresses equations (the number of data points) into equations (the number of parameters). The practical content of the theorem is that however many hundreds of millions of data points there are, the size of the linear system to be solved is determined by the number of features alone. We next investigate when that system has a unique solution.
Lemma 3.3(The kernel of the Gram matrix)
For every we have . Consequently , and the matrix is invertible if and only if the column vectors of are linearly independent.
Proof(Lemma 3.3)
If , multiplying on the left by gives , so . Conversely, suppose . Taking the inner product of both sides with ,
and only the zero vector has norm , so . Hence the two kernels coincide.
As for the ranks, applying the rank–nullity theorem(Theorem 7.3)[Vector Spaces and Linear Maps] to the two linear maps on gives
Finally, invertibility of is equivalent to , which is equivalent to ; and says that only for , which is exactly linear independence of the columns of . For the relation between linear maps and kernels see Vector spaces and linear transformations.
Corollary 3.4(Closed form for the least-squares solution)
If the column vectors of are linearly independent (that is, , which in particular forces ), then has exactly one minimiser, given by
Proof(Corollary 3.4)
By Lemma 3.3, is invertible, so the normal equation has the unique solution . By Theorem 3.2 the set of solutions of the normal equation coincides with the set of minimisers of , so this single point is the only minimiser.
Remark 3.5(When the columns are not linearly independent)
Minimisers exist even when . Indeed, from we get , while Lemma 3.3 gives , and equality of row rank and column rank gives . An inclusion between subspaces of equal dimension is an equality, so , and the right-hand side always lies in the left-hand side. That is, the normal equation always has a solution.
The solution is not unique, however: given one solution , the set of all solutions is the affine subspace . In practice uniqueness is imposed by ridge regularisation (minimising ) or by the Moore–Penrose pseudoinverse(Definition 8.6)[Linear Regression and Least Squares].
The condition used in the proof of Theorem 3.2 reads , that is, the residual vector is orthogonal to every column of . This is the geometric meaning of least squares. Equivalently, is nothing other than the orthogonal projection of onto the column space , a viewpoint treated head-on in Theorem 4.2[Linear Regression and Least Squares].
Example 3.6(Fitting a line to three points, carried through to the end)
Take the data and the model . Placing the constant feature in the first column,
(here , , , and ). Since , Corollary 3.4 applies. In the normal equation
multiplying the first equation by gives ; subtracting this from the second gives , that is, . Substituting back into the first gives , so . The fitted line is .
As a check, look at the residuals. The predicted values are , and , so
The inner product with the first column (all s) is , and with the second column it is . The residual is indeed orthogonal to both columns. The minimum value is .
Example 3.7(Duplicated features destroy uniqueness of the solution)
For the same data, suppose we accidentally include both "" and "" as features (for instance, entering a height as two columns, one in centimetres and one in metres). The design matrix is
and since the third column is twice the second, the columns are linearly dependent. Indeed for , so by Lemma 3.3 the matrix is not invertible.
The column space of is the same as that of (the third column, being a constant multiple of the second, adds no new direction), so neither the minimum loss value nor the prediction vector differs from Example 3.6. What changes is the number of solutions. The vector is one minimiser, but as stated in Remark 3.5, so is every
Indeed the prediction made by this is , independent of . The problem of multicollinearity, that reading meaning into the coefficient values themselves is dangerous, is in the language of linear algebra nothing more than the statement that the kernel of the design matrix is nontrivial.
4. Calculus: translating minimisation into the language of gradients
Section titled “4. Calculus: translating minimisation into the language of gradients”Theorem 3.2 relied heavily on the special form of the squared loss. Change the loss, or make the model nonlinear, and such closed forms are essentially never available. What is needed instead is a method that approaches a minimiser using only local information, namely derivatives. We first make clear what we should be aiming at.
Definition 4.1(Convex function)
A function is convex if for all and all ,
That is, the segment joining any two points on the graph never dips below the graph.
Theorem 4.2(For convex functions, stationary points and global minimisers coincide)
Let be totally differentiable.
- If is convex, then for all .
- If is convex, then is a global minimiser of if and only if . Moreover, the implication ” is a global minimiser ” holds without assuming convexity.
Proof(Theorem 4.2)
(1) Put and take . Since , the inequality of Definition 4.1 reads
Moving to the left and dividing by ,
By total differentiability, , so the left-hand side converges to as . The right-hand side is a constant independent of , so passing to the limit gives .
(2) First assume . Taking in (1) gives for every , so is a global minimiser.
Conversely, assume is a global minimiser. Take arbitrarily and consider the one-variable function . By the chain rule is differentiable with . Since attains its minimum at , the necessary condition for an extremum at an interior point (Fermat's lemma(Lemma 2.5)[Mean Value Theorems and Taylor's Theorem]) gives , that is, . Taking gives , hence . Convexity was never used in this direction.
The use of this theorem is plain. For a nonconvex function, “the gradient vanishes” is only a necessary condition, and one may have come to rest at a saddle point or a local minimiser. Convexity removes that worry: “making the gradient vanish” becomes exactly the same thing as “minimising”. The squared loss lies on the good side of this divide.
Remark 4.3(The squared loss is convex)
Put . For the identity
is verified by expansion alone (expanding the left-hand side gives , and ), so is convex in the sense of Definition 4.1. Next, putting ,
(using ). That is, an affine map sends convex combinations to convex combinations. Hence , so too is convex.
Therefore, by part (2) of Theorem 4.2, solving the normal equation and minimising are equivalent. We proved Theorem 3.2 without using differentiation at all precisely to show that this fact is visible with algebra alone. One and the same fact has three faces: algebraic (the normal equation), geometric (orthogonal projection) and analytic (stationary point).
4.1. Why an iterative method rather than a closed form
Section titled “4.1. Why an iterative method rather than a closed form”Given the formula of Corollary 3.4, it might seem that one need only evaluate it. In practice, iterative methods are used, for two reasons.
- Cost. Forming takes operations and solving the system takes . Once the number of features is of the order of or , this is out of reach.
- Scope. For models such as neural networks, where is nonlinear in , the equation is a nonlinear system and has in general no closed-form solution.
So we descend a little at a time, using only the gradient at the current point. With a constant learning rate , the rule
defines gradient descent. Part (1) of Theorem 4.2 can be read as saying that the gradient is the slope of a first-order approximation supporting the function from below, so moving in the opposite direction is a natural choice. But how large a step should we take? For the squared loss the answer can be written down completely.
Theorem 4.4(Convergence of gradient descent for the least-squares loss)
Let the column vectors of be linearly independent, and put and . Then is symmetric positive definite; list its eigenvalues with multiplicity as . Let be the unique minimiser of Corollary 3.4, let be a constant, and define the sequence by .
- One has for every initial point if and only if .
- If , then setting we have , and for every .
- The learning rate minimising is , and then , where is the condition number of .
Proof(Theorem 4.4)
Step 1 ( is symmetric positive definite). From , the matrix is symmetric. Moreover, for we have , and linear independence of the columns together with Lemma 3.3 gives , so this is positive. The eigenvalues of a symmetric matrix are real, and positive definiteness makes them all positive.
Step 2 (recursion for the error). By Lemma 3.1, . Since satisfies the normal equation (Theorem 3.2), we have , and therefore
Writing the error as ,
hence .
Step 3 (spectral decomposition). Since is real symmetric, the spectral theorem provides an orthonormal basis of with (Corollary 4.3[スペクトル定理]; for the full statement see The spectral theorem). Expanding with and using repeatedly gives
The second identity uses orthonormality of the basis.
Step 4 (claim 1). If for every , then each term of the finite sum above tends to as , so . For and ,
and requiring this for every is equivalent to the single condition on the largest eigenvalue. Conversely, if then . Taking the initial point gives and otherwise, so , and there exists an initial point from which the iteration fails to converge.
Step 5 (claim 2). Since , the quantity is decreasing in , so . If a real number lies in a closed interval then and , so . Hence (the endpoints being attained at and ), and the formula of Step 3 gives
Taking square roots gives the claim. By Step 4, when .
Step 6 (claim 3). We examine for . From we get , and there are three cases.
- For , both and are nonnegative, so , which is strictly decreasing in .
- For , we have . The first expression decreases and the second increases, so the maximum is smallest where the two are equal. Solving gives , and from this value lies in the interval (indeed is equivalent to , and is equivalent to , both of which hold).
- For , we have , strictly increasing.
Hence attains its minimum at , with value
(the last step divides numerator and denominator by ).
This theorem answers both questions 1 and 2 raised at the outset. Raising the learning rate too far makes the iteration diverge because it crosses into , and the speed of convergence is governed by the condition number alone. When is large, approaches and the number of iterations required grows roughly in proportion to . Let us see this in numbers.
Example 4.5(The condition number decides the number of iterations)
For the data of Example 3.6, . The characteristic polynomial is (the trace is and the determinant is ), so
By Theorem 4.4, the convergence condition is and the optimal learning rate is . The condition number is , so . To shrink the error by a factor of ,
so iterations are needed. Moreover the gap between the upper limit for convergence and the optimal value is tiny, so a slightly greedy choice makes the iteration diverge.
Now centre the input, setting (the mean of is ). The second column of the design matrix becomes , whose inner product with the first column is , so
Now and , so the number of iterations required is , that is, .
| without centring | with centring | |
|---|---|---|
| eigenvalues | ||
| condition number | ||
| learning rates that diverge | ||
| optimal learning rate | ||
| convergence rate | ||
| iterations to shrink the error by |
The fitted line is still ; all we changed was the choice of coordinates. That alone cut the number of iterations by a factor of . This is the answer to question 2.
5. Probability and statistics: where the loss comes from and what it guarantees
Section titled “5. Probability and statistics: where the loss comes from and what it guarantees”So far the loss function has been handed down from above. Why the square? Why not the absolute value? And why the cross-entropy for classification? Probability gives a principled answer to these questions.
Definition 5.1(Maximum likelihood estimation)
Given a probability model with parameter and observed data , the map , regarded as a function of , is called the likelihood function. A maximiser of the likelihood is called a maximum likelihood estimator. Since the logarithm is strictly increasing, this is equivalent to maximising the log-likelihood , or to minimising the negative log-likelihood.
Theorem 5.2(Under Gaussian noise, maximum likelihood coincides with least squares)
Let be fixed (nonrandom) inputs, let be a known constant, and suppose the observations are generated by
where are independent with the normal distribution . Then the set of maximum likelihood estimators of coincides with the set of minimisers of the squared loss .
Proof(Theorem 5.2)
Since , for fixed the variable is normally distributed with mean and variance . The are independent, so are independent too and the joint density is a product.
Taking logarithms turns the product into a sum:
The first term is a constant independent of , and the coefficient in the second is positive. Hence the set of maximising and the set of minimising are exactly the same. Multiplying by the positive constant does not change the minimisers, so this set coincides with the set of minimisers of .
In other words, the choice to “use the squared loss” is equivalent to the assumption that the errors are normally distributed, have the same spread at every data point, and are mutually independent. Choosing a loss function is implicitly choosing a probability model. If the assumptions do not match reality, the loss should be changed; for data contaminated by outliers, for instance, it is natural to assume a heavy-tailed distribution (Exercise 7.3).
Example 5.3(The cross-entropy comes from the Bernoulli distribution)
Consider binary classification. The labels are and the model outputs the probability that the label is :
(here is the sigmoid function, whose range is the open interval ). Assuming the are independent with Bernoulli distribution , and using , the probability of a single point can be packed into the single expression (which returns when and when ). Hence
and the right-hand side is precisely the cross-entropy loss. This is the answer to question 4. The difference between the squared loss and the cross-entropy is nothing more than a difference of probability model: whether the output is viewed as a real number or as a probability.
Let us also compute the gradient. From we get and , so for the loss at a single point, ,
By the chain rule, , and therefore
This has the same shape as from Lemma 3.1. The structure “apply the transpose of the design matrix to the residual” is common to linear regression and logistic regression. This form of the gradient is established again in Theorem 5.1[Logistic Regression]; the details are treated in Logistic regression.
5.1. Why the training error may be trusted, and why it may not
Section titled “5.1. Why the training error may be trusted, and why it may not”The other reason probability is needed is to justify the substitution of for in Definition 2.2.
Proposition 5.4(For a fixed predictor, the empirical risk concentrates around the expected risk)
In the setting of Definition 2.1, let be drawn independently from the distribution , all with the same distribution. Suppose the predictor is fixed in advance and does not depend on the training data, and that the random variables have finite expectation and finite variance . Then the following hold.
- (unbiasedness).
- .
- For every , .
Proof(Proposition 5.4)
We have . The are independent and identically distributed with (since does not depend on the data, the distribution of is determined by and alone).
- By linearity of expectation, .
- The variance of a sum of independent random variables is the sum of the variances, so ; and since , we get .
- Applying Chebyshev's inequality(Corollary 6.2)[Random Variables and Expectation] to the random variable , with mean and variance , gives the bound immediately.
For linearity of expectation, additivity of variance for independent random variables, and Chebyshev’s inequality, see Random variables and expectation and The law of large numbers and the central limit theorem.
Claim 3 says that increasing brings the training error close to the generalisation error in the sense of probability. Since appears in the denominator, it also yields a quantitative guideline: to halve the accuracy , take four times as many samples. This is the most naive mathematical backing for the rule of thumb that more data is better.
Remark 5.5(What breaks when the assumption that f is independent of the data is dropped)
Given distinct points , there always exists a polynomial of degree at most passing through all points (Lagrange interpolation; the coefficient matrix of the linear system determining the coefficients is a Vandermonde matrix, whose determinant is when the points are distinct, so the matrix is invertible). Choosing this polynomial makes the empirical risk exactly .
The expected risk of this predictor, however, is in general enormous, and it oscillates wildly between the training points. This looks like a contradiction with Proposition 5.4, but it is not. The polynomial was determined after looking at the training data, so the hypothesis of the proposition, that does not depend on the data, fails. When is chosen as a function of the data, neither the independence of the nor the identity holds.
This is what overfitting really is, and it is the answer to question 3. As long as we select from within a hypothesis class , what we actually need is not a bound for each individual but a uniform bound on . Controlling this quantity by the “size” of the hypothesis class is the subject of statistical learning theory (VC dimension, Rademacher complexity, and so on).
6. The division of labour among the three areas, and what comes next
Section titled “6. The division of labour among the three areas, and what comes next”All four questions raised at the outset now have answers.
- Raising the learning rate makes the iteration diverge. Because at the error along the direction of the largest eigenvalue is amplified (Theorem 4.4).
- Changing the units speeds up convergence. Because the condition number changes and the convergence rate improves (Example 4.5).
- The training error is yet the model misses. Because unbiasedness of the empirical risk is lost the moment the model is chosen after looking at the data (Remark 5.5).
- Regression and classification use different losses. Because the probability model placed on the output is normal in one case and Bernoulli in the other (Theorem 5.2, Example 5.3).
The division of labour among the three areas of mathematics can be summarised as follows.
| Stage of learning | Mathematics chiefly used | Concrete instance seen here | Read on |
|---|---|---|---|
| Representing data and models | linear algebra (matrices, subspaces, orthogonal projection) | design matrix, normal equation, orthogonality of the residual | Linear regression and least squares |
| Compressing and diagnosing representations | linear algebra (eigenvalues, symmetric matrices) | the condition number decides the iteration count | Principal component analysis |
| Minimising the loss | calculus (gradients, convexity, limits) | the bound on the learning rate and its optimal value | Gradient descent |
| Computing gradients in deep models | calculus (chain rule) | the derivative through the sigmoid | Neural networks and backpropagation |
| Designing the loss | probability and statistics (likelihood) | squared loss from Gaussian noise, cross-entropy from Bernoulli | Logistic regression |
| Assessing uncertainty | probability and statistics (expectation, law of large numbers) | unbiasedness of the empirical risk and its variance | Probability and Bayesian statistics |
The prerequisites are, for linear algebra, Vector spaces and linear transformations, Inner product spaces and Gram–Schmidt orthogonalisation and Eigenvalues and eigenvectors; for calculus, Differentiation of multivariable functions and partial derivatives and The mean value theorem and Taylor’s theorem; and for probability, Probability spaces and Kolmogorov’s axioms and Random variables and expectation. No deep excursion is required. All this article actually used was the relation between the inner product and the transpose, the rank–nullity theorem, the spectral theorem for symmetric matrices, the definition of total differentiability, linearity of expectation, and Chebyshev’s inequality.
7. Exercises
Section titled “7. Exercises”Exercise 7.1Easy
For the data , find the least-squares solution for the model from the normal equation. Then verify that the resulting residual vector is orthogonal to both columns of the design matrix.
Solution
The design matrix and target vector are
Then (the is the number of rows, , ) and (, ). Since , the solution is unique by Corollary 3.4. The normal equation is
Multiplying the first equation by gives ; subtracting from the second gives , so . The first equation then gives , so . The line is .
The predicted values are , so the residual is . Its inner product with the first column is , and with the second column it is . This is nothing but the componentwise form of from Theorem 3.2.
Exercise 7.2Standard
Let . This is for , and the minimiser is the origin.
- Find the range of learning rates for which gradient descent converges from every initial point.
- Find the giving fastest convergence, and the corresponding convergence rate .
- Using the from part 2, find a number of iterations sufficient to guarantee .
Solution
We have , and since is diagonal its eigenvalues are simply and , with the standard basis as eigenvectors. Theorem 4.4 applies directly (with ).
- By claim 1, .
- By claim 3, , and since we get .
- By the bound in claim 2 it suffices that . Taking logarithms gives , and since ,
so iterations suffice. A condition number of , which is hardly extreme, already forces several hundred iterations. The value of putting features on a common scale shows itself here.
Exercise 7.3Standard
In the same setting as Theorem 5.2, suppose the noise is independent with the Laplace density , where is known.
- Derive which function maximum likelihood estimation of amounts to minimising.
- Explain, in terms of how the loss grows with the residual, why the resulting loss is less sensitive to outliers than the squared loss.
Solution
- By independence the joint density is a product:
Taking the negative logarithm,
The first term is a constant independent of and the coefficient of the second is positive, so by Definition 5.1 maximum likelihood is equivalent to minimising , that is, to the absolute-value loss (least absolute deviations regression).
- For the residual , the contribution of the squared loss is , its derivative with respect to the residual is , and its contribution to the gradient is . Moving one observation far away makes the contribution grow without bound in proportion to , so that single point drags the solution around. The contribution of the absolute-value loss, by contrast, is , its derivative at is , and its contribution to the gradient is , which is bounded. However far out a point lies, the size of its influence is capped.
In the language of probability models: the normal density decays rapidly as , so it judges large residuals to be all but impossible and works hard to exclude them, whereas the Laplace distribution has heavy tails, , and regards large residuals as reasonably possible. Note, though, that the absolute-value loss is not differentiable at , so optimisation requires subgradient methods or a reformulation as a linear program.
References
Section titled “References”- M. P. Deisenroth, A. A. Faisal, C. S. Ong, Mathematics for Machine Learning, Cambridge University Press, 2020 — Chapter 2 (linear algebra), Chapter 5 (vector calculus), Chapter 9 (linear regression). A full version released by the authors is available at mml-book.github.io.
- C. M. Bishop, Pattern Recognition and Machine Learning, Springer, 2006 — Chapter 1 (decision theory and loss functions), Chapter 3 (linear regression and maximum likelihood), Chapter 4 (classification and logistic regression).
- I. Goodfellow, Y. Bengio, A. Courville, Deep Learning, MIT Press, 2016 — Part I (Chapter 2 linear algebra, Chapter 3 probability and information theory, Chapter 4 numerical computation, Chapter 5 machine learning basics). Available at deeplearningbook.org.
- S. Boyd, L. Vandenberghe, Convex Optimization, Cambridge University Press, 2004 — Chapter 3 (convex functions and the first-order condition), Chapter 9 (unconstrained minimisation and the convergence analysis of gradient descent). Available at web.stanford.edu/~boyd/cvxbook/.
- S. Shalev-Shwartz, S. Ben-David, Understanding Machine Learning: From Theory to Algorithms, Cambridge University Press, 2014 — Chapter 2 (empirical risk minimisation and overfitting), Chapter 4 (uniform convergence).
- S. M. Stigler, The History of Statistics: The Measurement of Uncertainty before 1900, Harvard University Press, 1986 — Part I treats the story of Legendre and Gauss around the method of least squares.
Report an error in this article ・Operated by: Mugen Giken LLC ・Pricing ・Terms ・Legal notice
© 2026 夢現技研合同会社 ・Feeding the text to an LLM is welcome. Code samples are MIT licensed.