दुर्गा बेरागी Durga Beragi, homeEnter the study →

Library › Artificial intelligence

The Elements of Statistical Learning

Trevor Hastie, Robert Tibshirani and Jerome Friedman · 2001 · Springer

Statistics underneath machine learning, written by statisticians.

About the book

Trevor Hastie, Robert Tibshirani and Jerome Friedman, statisticians at Stanford, published this book in 2001 through Springer. A second edition appeared in 2009, and the authors make it free to download. The book presents machine learning from a statistical point of view, written by people who created several of its methods, including the lasso, generalised additive models and gradient boosting. It focuses mainly on supervised learning. Chapters cover linear methods for regression and classification, basis expansions and regularisation, kernel smoothing, model assessment and selection, model inference and averaging, additive models and trees, boosting, neural networks, support vector machines, nearest-neighbour methods and unsupervised learning. The second edition added random forests, graphical models and high-dimensional problems.

Key ideas

  • Prediction from data faces a trade-off between bias and variance. Simple models miss real structure, while flexible models fit noise, and good methods find a balance between the two.
  • Regularisation controls complexity by penalising large coefficients. Ridge regression shrinks all of them toward zero, while the lasso can set some exactly to zero, which also selects variables.
  • Model performance must be judged on data not used for fitting. Cross-validation and the bootstrap estimate how well a model will do on new data.
  • Trees split data into simple rectangular regions. Alone they are unstable, but combining many trees through bagging, boosting or random forests produces some of the strongest predictors available.
  • Boosting builds a model step by step, each step correcting the errors of the last. The authors show it can be understood as fitting an additive model by gradient descent.
  • Many methods share one structure: choose a class of models, a loss function and a penalty, then fit. Seeing this shared structure connects methods that at first look unrelated.

Why it is on this shelf

Most practical machine learning on business data still uses the methods in this book: regularised regression, trees and boosting. It explains why they work and when they fail, which protects against overfitting and false confidence. It is demanding but exact.

How to start reading it

Read chapters two and three on overview and linear methods, then chapter seven on model assessment. Read the chapters on trees and boosting next. If the mathematics is heavy, read An Introduction to Statistical Learning by the same group first.

About this book

The Elements of Statistical Learning, with the subtitle Data Mining, Inference, and Prediction, was written by Trevor Hastie, Robert Tibshirani and Jerome Friedman, all of the statistics department at Stanford University. Springer published the first edition in 2001 in its series on statistics. A second edition, substantially enlarged, appeared in 2009, and it has been reprinted with corrections many times since. The authors arranged for a PDF of the second edition to be offered free from their website, which made it one of the most widely read technical books in its field.

The book was written at a particular moment. Through the 1990s, computing power and stored data had grown fast, and a set of new methods for learning from data had appeared, many of them outside statistics departments. Computer scientists had neural networks, support vector machines and boosting. Database researchers spoke of data mining. Statisticians had their own new tools, such as generalised additive models, tree-based methods and the bootstrap. The communities used different words for related ideas and did not always read each other. Many statisticians regarded machine learning as unprincipled, and many machine learners regarded statistics as slow and narrow.

The question the book sets out to answer is how this growing collection of methods fits together when seen from statistics. What problem is each method solving, what assumptions does it make, why does it work when it works, and how should one choose among methods and judge the result? The authors' answer is that most of these techniques are versions of a few ideas: fitting a function from inputs to an output, controlling the complexity of that function, and estimating how well it will perform on new data.

The intended readers are graduate students and researchers in statistics, computer science, engineering and the quantitative sciences, as well as practitioners who use these methods and want to understand them properly. The book assumes linear algebra, calculus, probability and a first course in statistics, including linear regression. It is not a programming manual. It contains almost no code and focuses instead on concepts, derivations and many carefully chosen figures. Its colour illustrations, unusual for a statistics text when first published, are part of how it teaches.

The book's emphasis is supervised learning, where each training example comes with a known answer and the aim is to predict the answer for new cases. The final chapters treat unsupervised learning, where there is no answer to predict and the aim is to find structure. Throughout, the voice is that of working statisticians who invented several of the methods they describe, and who want readers to see both the power and the limits of each.

The authors

Three statisticians at Stanford

Trevor Hastie grew up in South Africa and took his doctorate in statistics at Stanford in the mid 1980s. He then spent several years at AT&T Bell Laboratories, which at the time was a lively centre for statistical computing, before returning to Stanford as a professor. Robert Tibshirani, a Canadian, also took his Stanford doctorate in the mid 1980s, under Bradley Efron, the inventor of the bootstrap. He taught at the University of Toronto before moving back to Stanford. Together, Hastie and Tibshirani developed generalised additive models, which extend linear regression by letting each input enter through a flexible smooth curve. Their book Generalized Additive Models appeared in 1990.

Tibshirani is best known for the lasso, introduced in a paper published in 1996, a method of regression that shrinks coefficients and sets some of them exactly to zero. The lasso became one of the most cited ideas in modern statistics and the starting point for a large field of sparse methods. With Efron he wrote An Introduction to the Bootstrap, published in 1993. Hastie's work ranges across smoothing, principal curves, classification and, later, efficient algorithms and software for fitting regularised models, including the widely used glmnet package for the R language, written with Friedman and Tibshirani.

Jerome Friedman came to statistics from physics. He trained as a physicist at the University of California, Berkeley, and worked for many years in the computation group at the Stanford Linear Accelerator Center while holding a professorship in statistics. His contributions are some of the most practical in the field. With Leo Breiman, Richard Olshen and Charles Stone he wrote Classification and Regression Trees in 1984, which established tree-based methods. He developed projection pursuit regression, multivariate adaptive regression splines and, around 2000, gradient boosting machines, which remain among the most effective tools for prediction on tabular data.

Their later books

The three authors, with colleagues, later wrote several related books. An Introduction to Statistical Learning, by Gareth James, Daniela Witten, Hastie and Tibshirani, appeared in 2013 as a gentler version of this book with exercises in R, and later editions added Python. Statistical Learning with Sparsity, by Hastie, Tibshirani and Martin Wainwright, appeared in 2015 and develops the lasso and its relatives in depth. Efron and Hastie wrote Computer Age Statistical Inference in 2016, a reflection on how computing changed the discipline. Reading any of these alongside this volume shows a consistent outlook: statistics as a practical science of learning from data, aided by computation, and accountable to performance on new cases.

The fact that the authors created several of the methods they describe gives the book its particular character. They explain methods from the inside, with a sense of why a method was designed as it was and where its weak points lie. The same fact also brings a natural bias toward their own tools, which a reader should keep in mind when the book compares approaches.

It helps to know what the title promises. The word elements signals a book of foundations, in the old sense of a work that sets out the basic parts from which a subject is built. The three words of the subtitle, data mining, inference and prediction, name the three communities the authors hoped to address: those who search large data sets for patterns, those who reason about uncertainty in estimates, and those who want accurate forecasts. The book does not give these three aims equal space. Prediction dominates, inference appears where it supports prediction, and data mining appears mostly through the methods the authors judge sound.

The book also takes a clear stance on the role of the computer. For much of the twentieth century, statistical methods were designed so that they could be computed by hand or with modest machines. Many of the methods here, such as cross-validation, the bootstrap, boosting and random forests, would be impractical without fast computation. The authors treat this not as a weakness but as a change in what statistics can be. Problems once handled with elegant formulas and strong assumptions can now be handled with repeated computation and weaker assumptions. This shift in outlook is one of the book's quiet lessons.

The shape of the argument

The book is built around a single framework introduced early and then developed in many directions. The framework treats learning as estimating an unknown function that maps inputs to an output, given a finite set of examples. Any method must make some assumption about what kind of function to look for, because without one there are infinitely many functions that fit the data perfectly and predict nothing. The various methods differ mainly in the assumption they make and in how they control the flexibility of the fitted function.

The first movement of the book sets out this framework and studies the simplest family in detail: linear models for regression and classification. This is not a warm-up. The authors return to linear methods again and again, because they are the baseline, because many complex methods reduce to them in special cases, and because the central tensions of the whole subject, between fit and complexity, and between bias and variance, can be seen there most clearly.

The second movement extends the reach of linear methods without abandoning their structure. Inputs can be transformed through basis functions such as splines; neighbourhoods can be used to fit local models; kernels can define similarity. At this point the book pauses for a long discussion of how to assess and select models, which is in many ways its intellectual centre, followed by discussion of inference, averaging and the bootstrap.

The third movement covers the families of method that dominated practice at the time of writing and since: additive models, trees and related methods, boosting, neural networks, support vector machines and nearest-neighbour methods. Each is shown as an answer to the same underlying problem, with its own way of controlling complexity. The final movement turns to unsupervised learning and, in the second edition, to random forests, ensemble learning, graphical models and problems in which there are more variables than observations.

Throughout, the book argues more by demonstration than by theorem. A typical section introduces a method, derives it, shows a figure comparing it with alternatives on simulated or real data, and then discusses what the comparison reveals. The figures are part of the argument. Many readers remember the book through them: decision boundaries drawn over a simulated mixture of two classes, coefficient paths sliding toward zero as a penalty grows, error curves that fall and then rise as complexity increases.

Learning as function estimation

The basic setup

The first key idea is that most of supervised learning can be described as estimating a function. We have inputs, such as a patient's age, blood pressure and test results, and an output, such as whether the patient has a disease. There is some true relationship between them, blurred by noise and by factors we have not measured. From a training set of examples we want to build a rule that gives good predictions for new patients. Whether the rule is called a regression model, a classifier, a neural network or a decision tree, it is a function from inputs to a predicted output.

To say what good means, we need a loss function, which measures how costly a wrong prediction is. For numeric outputs the usual choice is squared error. For categories it may be the rate of misclassification, or a smoother measure based on probabilities. Given a loss, there is a best possible function in principle, the one that minimises expected loss over the true distribution of the data. For squared error, it is the conditional mean of the output given the inputs. Every learning method is an attempt to approximate this ideal from limited data.

Two simple extremes

The book opens its argument with two simple methods placed side by side. Linear regression assumes the function is a weighted sum of the inputs. It is stable and easy to interpret, but if the true relationship is curved, it will be systematically wrong. The nearest-neighbour method makes almost no assumption: to predict for a new case, it averages the outputs of the closest training cases. It can fit any shape, but its predictions jump around with the particular sample, and it degrades badly when there are many inputs.

This contrast is the seed of the whole book. One method is rigid and steady, the other flexible and unstable. Almost every later method sits somewhere between them, trying to keep the steadiness of a structured model while gaining the flexibility to capture real patterns. Seeing methods this way helps a reader place an unfamiliar technique quickly by asking what structure it imposes and what freedom it allows.

The curse of dimensionality

The book stresses early why nearest-neighbour methods fail in high dimensions, a phenomenon called the curse of dimensionality. When there are many inputs, data points become sparse. To capture even a small fraction of the data in a neighbourhood, the neighbourhood must stretch across most of the range of each input, so it is no longer local. A useful image is a sheet of paper with a hundred dots, which looks crowded, compared with a large room with a hundred dots spread through its volume, which looks empty. With dozens of dimensions, every point is far from every other. Methods that rely on local averaging need structure from somewhere else, and that structure must come from assumptions.

This idea is often misunderstood as a claim that high-dimensional problems are hopeless. They are not, because real data usually have structure: inputs are correlated, only some matter, or the function is smooth in particular ways. The point is that success in high dimensions always depends on exploiting such structure, whether the analyst states it openly or the method builds it in silently.

Bias, variance and complexity

Two sources of error

The second key idea is the decomposition of prediction error into bias and variance. Imagine drawing many different training sets from the same population and fitting the same method to each. The predictions at a particular input will vary across fits. Their average may differ from the true value; that systematic difference is bias. The spread of predictions around their own average is variance. Expected prediction error, under squared loss, is the sum of squared bias, variance and an irreducible noise term that no method can remove.

A simple model has high bias and low variance. A flexible model has low bias and high variance. As complexity rises, training error always falls, because a more flexible model can always fit the training data better. But error on new data falls at first, as bias shrinks, then rises, as variance takes over. The best model sits at the bottom of this curve. The picture of a training error curve sliding steadily downward while the test error curve bends back up appears in many forms throughout the book.

An analogy

Consider tailoring. An off-the-peg shirt in a few standard sizes has bias: it fits nobody exactly. But it is reliable, and a shop can stock it without knowing each buyer. A shirt made to measure from a single hurried measurement may fit perfectly on the day it is measured and badly the next, because the measurement included errors. A good tailor measures carefully and also knows what sensible shirts look like, so that a strange measurement is corrected rather than followed. Learning methods face the same choice between imposing a template and following the noise.

Degrees of freedom

To compare methods of very different kinds, the book uses the notion of effective degrees of freedom. For a linear model with a given number of inputs, the degrees of freedom equal that number. For smoothers, penalised fits and other methods, a generalisation measures how strongly fitted values respond to changes in observed outputs. This gives a common scale of complexity across methods that look nothing alike. A smoothing spline and a ridge regression can be placed on the same axis and compared.

Bias and variance are sometimes misread as fixed properties of methods. They are properties of a method applied with a particular amount of data and a particular setting of its tuning parameters. With more data, variance falls, and more flexible methods become affordable. This is one reason why methods that failed on small data sets in earlier decades succeeded once large data sets became common. The trade-off has also been revisited in recent years, as discussed below, but the idea remains the first thing a practitioner should check.

Regularisation and the lasso

Shrinking to gain

The third key idea is that a model can be improved by deliberately making its estimates smaller. Ordinary least squares regression gives unbiased estimates of coefficients under standard assumptions, and for a long time unbiasedness was regarded as a virtue in itself. But when there are many inputs, or inputs are correlated, least squares estimates can vary wildly from sample to sample. Accepting a little bias in return for a large drop in variance usually lowers prediction error. Regularisation is the general name for methods that do this by adding a penalty on the size of the coefficients to the quantity being minimised.

Ridge regression penalises the sum of squared coefficients. It pulls all of them toward zero, and pulls hardest along directions in the data where there is little information. When two inputs are nearly copies of each other, least squares may give one a large positive coefficient and the other a large negative one. Ridge regression spreads the weight between them more sensibly. The strength of the penalty is a tuning parameter: at zero, ridge is least squares; as it grows, all coefficients approach zero.

The lasso

The lasso penalises the sum of the absolute values of the coefficients. This small change has a large effect. Because of the shape of the penalty, which has corners where coefficients are zero, the lasso sets some coefficients exactly to zero. It therefore performs shrinkage and variable selection together. In a problem with a hundred candidate inputs, the lasso may return a model that uses twelve, with the rest discarded. The result is easier to interpret and often predicts as well as or better than a model using all inputs.

The book presents the lasso through geometry. Picture the coefficients as a point in space, and the least squares error as a set of nested ellipses around the best fit. The ridge penalty is a circle, the lasso penalty a diamond. The constrained solution is where the smallest ellipse first touches the penalty region. A circle is touched at a generic point, so all coefficients are nonzero. A diamond tends to be touched at a corner, where some coefficients are zero. This figure is one of the most reproduced images in the field.

Paths and algorithms

Rather than choose one penalty strength, the book encourages looking at the whole path of solutions as the penalty varies. As the penalty relaxes, variables enter the lasso model one by one, and their coefficients grow. The least angle regression algorithm, developed by Efron, Hastie, Johnstone and Tibshirani, computes this path efficiently and reveals a close link between the lasso and older stepwise methods. Later, coordinate descent algorithms made it practical to fit lasso paths for very large problems. The second edition also discusses the elastic net, which mixes the ridge and lasso penalties to handle groups of correlated inputs better than the lasso alone.

Regularisation is sometimes confused with simply using fewer variables. It is broader. It is a way of encoding a preference for simpler explanations into the fitting procedure itself. The same idea appears throughout the book: in smoothing splines, where curvature is penalised; in neural networks, where weight decay is ridge regression by another name; in support vector machines, where the margin plays the role of the penalty; and in boosting, where small step sizes act as a form of shrinkage.

Drawing lines between classes

Two routes to a boundary

A further key idea concerns classification, where the output is a category rather than a number. The book shows that even here, the simplest methods are linear, and that there are two quite different routes to a linear boundary. The first route models how the inputs are distributed within each class and then uses Bayes' rule to work out which class a new case most probably belongs to. Linear discriminant analysis, going back to Ronald Fisher, takes this route, assuming each class has a bell-shaped distribution with a shared spread. The boundary between classes then turns out to be a straight line, or a flat plane in many dimensions.

The second route models the probability of each class directly as a function of the inputs, without describing how the inputs themselves are distributed. Logistic regression takes this route. It passes a linear combination of the inputs through an S-shaped curve to produce a probability between zero and one. Its boundary is also linear. The two methods often give similar answers, but they rest on different assumptions. Discriminant analysis uses more assumptions and so can be more efficient when they hold, and more misleading when they fail, for instance when inputs are far from bell-shaped or include categories.

Why the distinction matters

The difference between modelling how data are generated and modelling only the decision is one of the deepest in the subject. Later the same contrast reappears between methods that describe full probability distributions and methods, like support vector machines, that care only about the boundary. A useful analogy is with two ways of telling apples from oranges by weight and colour. One person builds a full picture of what apples look like and what oranges look like, then compares. Another learns only where the dividing line falls. The first knows more and can say how unusual a fruit is. The second needs less data to find the line, and is less harmed if the picture of apples is wrong.

The book also shows why using ordinary regression on a coded category output can fail when there are three or more classes, with one class masked by the others, and it discusses separating hyperplanes, the idea from which support vector machines later grow. These sections are short but repay careful reading, since they set up much that follows.

Flexible fits from simple pieces

Basis expansions

The fourth key idea is that a linear method can fit curved relationships if the inputs are first transformed. Instead of using age directly in a model, one can use age, age squared and age cubed, or a set of functions each active in a different range of ages. The model is still linear in its coefficients, so all the machinery of least squares and regularisation still applies, but the fitted function can bend. These transformed inputs are called basis functions.

Splines are the book's favourite basis. A cubic spline is built from cubic pieces joined smoothly at chosen points called knots. Natural splines add the constraint that the function is linear beyond the outer knots, which steadies the fit at the edges where data are thin. Smoothing splines take a bolder approach: put a knot at every data point, then control the wiggliness with a penalty on curvature. The penalty strength becomes the single knob that moves the fit from a straight line to a curve that passes through every point.

Local methods and kernels

A different route to flexibility is to fit simple models locally. To predict at a point, weight nearby training cases more heavily than distant ones and fit a straight line or a constant using those weights. The weighting function is called a kernel, and its width controls the bias and variance of the fit. Local linear regression corrects the bias that a local average suffers near the edges of the data, a detail the book handles carefully.

Kernels also appear in a more abstract sense. A kernel function can define a measure of similarity between any two inputs, and some methods can be written entirely in terms of such similarities. This allows a method to behave as if inputs had been expanded into a very large or even infinite set of basis functions without ever computing them. The book connects this to the theory of reproducing kernel Hilbert spaces, a mathematical framework in which smoothing splines and support vector machines turn out to be close relatives. This is one of the book's quieter achievements: it shows that methods from different communities are solving the same penalised problem in different spaces.

A common confusion is to think of these as separate methods to memorise. They are better understood as answers to one question: how do we let the data choose the shape of a function while preventing it from chasing noise? Every answer pairs a flexible family of functions with a way of restraining it.

Judging a model honestly

Training error deceives

The fifth key idea, and perhaps the most important for practice, is that a model must be judged on data it has not seen. Training error, the error on the data used to fit the model, is optimistic, and the more flexible the model, the more optimistic it is. A model can fit the training data perfectly and predict new data badly. The book devotes a central chapter to the assessment and selection of models, distinguishing two goals: choosing among models or tuning settings, and estimating the error of the final chosen model.

When data are plentiful, the cleanest approach is to split them into three parts: a training set for fitting, a validation set for choosing among models, and a test set used once at the end to estimate performance. The test set must stay untouched until the very end. If it is consulted repeatedly during model choice, it becomes another training set and its estimate becomes optimistic too.

Cross-validation and the bootstrap

When data are scarce, one cannot afford to set aside large portions. Cross-validation reuses data. Split the data into several folds, fit the model on all but one fold, test on the held-out fold, and repeat so that each fold is held out once. The average error estimates performance on new data. The book discusses the choice of the number of folds, the bias and variance of the estimate, and a widely made mistake: performing variable selection on the full data set before cross-validation. Because the selection step has already seen all the data, the resulting error estimate can be wildly optimistic. The correct procedure applies every step of model building, including selection, inside each fold.

The bootstrap, invented by Efron, resamples the data with replacement to imitate drawing new samples from the population. The book shows how bootstrap methods can estimate prediction error and the uncertainty of fitted quantities, and how naive versions can be biased because resampled sets overlap with the original data.

Criteria from theory

The book also covers analytic criteria that adjust training error for complexity, including the Akaike information criterion, the Bayesian information criterion, minimum description length and the Vapnik Chervonenkis dimension from learning theory. These give quick estimates without refitting, and each rests on assumptions about the model. The authors treat them fairly but favour cross-validation in practice because it depends least on assumptions.

This chapter's ideas are now standard in industry, but the errors it warns against remain common. Leakage of information from test data into training, tuning on the test set, and selecting features before validation all produce models that look excellent in development and disappoint in use. A reader who absorbs this chapter will avoid most of them.

Inference and the wisdom of averages

From fitting to uncertainty

Another key idea, developed in the chapter on model inference and averaging, is that fitting a model and knowing how uncertain the fit is are separate tasks. The book connects three ways of thinking about uncertainty. Maximum likelihood finds the parameter values that make the observed data most probable and uses the curvature of the likelihood to estimate uncertainty. The bootstrap estimates uncertainty by refitting on resampled data. Bayesian methods treat parameters as uncertain from the start and update a prior distribution into a posterior. The authors show that in simple cases the three agree closely, and that the bootstrap can be seen as a rough, assumption-light version of Bayesian reasoning.

The chapter also explains the expectation maximisation algorithm, a general method for fitting models with missing data or hidden variables. The algorithm alternates between guessing the hidden quantities given the current parameters and re-estimating the parameters given those guesses. Mixture models, in which data come from several unlabelled groups, are the standard example. Markov chain Monte Carlo is introduced briefly as a way of sampling from complex posterior distributions.

Averaging rather than choosing

Most model selection picks one winner. The book argues that combining models is often better than choosing among them. Bayesian model averaging weights each model by its posterior probability. Committee methods simply average. Stacking, introduced by David Wolpert and developed by Breiman, learns the weights by cross-validation, so that the combination is chosen to predict well on held-out data. Bagging appears here too, as the first example of averaging over models fitted to perturbed data.

Averaging works because different models make different errors, and errors that are not perfectly correlated partly cancel. This is the statistical version of an old observation about the judgement of crowds, with the same condition attached: the members must not all share the same mistake. The idea is often confused with simply making a model larger. The point is diversity among the parts, and it leads directly into the next chapters on ensembles of trees.

Trees and their ensembles

Rectangles in the input space

The sixth key idea is that decision trees, though weak on their own, become very strong when many are combined. A regression or classification tree divides the input space into rectangles by a sequence of yes or no questions, each about one input. Is income above a threshold? If so, is age below another? Each final region predicts a constant, the average output or the most common class of the training cases inside it. Trees are grown by choosing at each step the split that most reduces error, then pruned back to avoid overfitting, with the amount of pruning chosen by cross-validation.

Trees have attractive features. They handle mixed types of input, ignore irrelevant variables fairly well, capture interactions naturally, and can be read by a non-specialist. But they have two serious weaknesses. Their predictions are coarse, since they are constant within each rectangle. And they are unstable: a small change in the data can change an early split and therefore the whole tree. In the language of the earlier chapter, trees have high variance.

Bagging and random forests

Bagging, short for bootstrap aggregating, attacks the variance directly. Draw many bootstrap samples, grow a tree on each, and average their predictions. Averaging many unstable estimates that are not perfectly correlated reduces variance. Random forests, introduced by Leo Breiman and given a full chapter in the second edition, go further. At each split, the tree may only choose among a random subset of the inputs. This makes the trees less alike, so that averaging reduces variance more. Random forests require little tuning, work well on many problems, and provide an internal estimate of error from the cases left out of each bootstrap sample.

The book also discusses variable importance measures and partial dependence plots, which try to restore some of the interpretability lost when one tree becomes hundreds. These tools are useful but should be read with care. Importance measures can favour inputs with many possible split points, and partial dependence can mislead when inputs are strongly correlated.

Ensembles are sometimes taken as a black-box trick. The book shows that their success is explained by the bias and variance analysis: they keep the low bias of deep trees and remove much of their variance. That explanation also tells when they will fail, for instance when all trees make the same systematic error.

Boosting as additive modelling

Learning from mistakes

The seventh key idea is the statistical understanding of boosting, a contribution in which the authors played a leading part. Boosting came from computer science. The AdaBoost algorithm of Yoav Freund and Robert Schapire, published in the mid 1990s, combined many weak classifiers, each barely better than guessing, into a strong one. It worked by fitting a sequence of classifiers, each giving more weight to the cases that earlier classifiers got wrong. Its performance was remarkable and, at first, somewhat mysterious, since it seemed to resist overfitting even after very many rounds.

Friedman, Hastie and Tibshirani showed that AdaBoost can be understood as fitting an additive model one term at a time, a method called forward stagewise modelling, while minimising a particular loss function, the exponential loss. This view placed boosting inside statistics. It explained what boosting was estimating, connected it to logistic regression, and suggested other loss functions that would be more robust to mislabelled data.

Gradient boosting

Friedman then generalised the idea. For any differentiable loss, one can think of fitting a model as moving downhill on the loss, with each new tree approximating the direction of steepest descent, the negative gradient, evaluated at the training points. This gives gradient boosting, which can handle regression, classification, ranking and other tasks with one framework. The book stresses the practical refinements that make it work well: shrinking each step by a small learning rate, using small trees of limited depth, and fitting each tree on a random subsample of the data.

An analogy helps. Imagine a team correcting a long document. The first editor fixes the most obvious problems. The second reads the result and fixes what remains. Each editor makes only modest changes, and the team stops before editors begin introducing new errors. The final text is the sum of many small corrections. Gradient boosting is that process carried out with trees as editors and a loss function as the standard of quality.

Boosting is sometimes confused with bagging, since both combine many trees. The difference matters. Bagging grows trees independently and averages them to reduce variance. Boosting grows trees in sequence, each depending on the last, and mainly reduces bias. Later software packages built on this framework dominate prediction tasks on structured, tabular data to this day.

Margins, networks and a common frame

Support vector machines

The eighth key idea is that methods from machine learning, which arrived with their own vocabulary and motivation, can be expressed as a loss function plus a penalty. Support vector machines were introduced by Vladimir Vapnik and colleagues from learning theory, with the goal of finding a boundary between classes that leaves the widest possible margin. The book shows that the support vector classifier is equivalent to minimising a particular loss, the hinge loss, with a ridge-style penalty on the coefficients. With kernels, it becomes a penalised fit in a reproducing kernel Hilbert space, the same framework used for smoothing splines.

Once seen this way, the support vector machine stands beside logistic regression rather than in another world. The two losses behave similarly for cases near the boundary and differently for cases far from it. Logistic regression gives probabilities; the support vector machine focuses only on the boundary. Choosing between them becomes a matter of what one wants, not of which community one belongs to.

Neural networks

The book's chapter on neural networks treats them in the same spirit. A single hidden layer network is shown to be a kind of projection pursuit regression, a method Friedman had developed earlier, in which the output is a sum of nonlinear functions of linear combinations of the inputs. Training by back-propagation is gradient descent on a loss. Weight decay is a ridge penalty. Early stopping is an implicit form of regularisation. The authors discuss practical issues such as starting values, scaling of inputs and the number of hidden units.

Read today, this chapter is the book's most dated, because it was written before the rise of deep learning. It does not cover convolutional networks in depth or the training of very large networks. Yet its framing remains useful: a network is a flexible function family trained by minimising a penalised loss, and the questions of bias, variance and honest validation apply to it as to everything else.

The unifying recipe

The common frame can be stated in one line: choose a family of functions, a loss that measures error and a penalty that measures complexity, then minimise loss plus penalty, with the balance chosen by validation. Linear regression, ridge, lasso, splines, support vector machines, boosting and neural networks all fit this recipe. The idea is easy to state and hard to absorb fully. Once absorbed, it lets a reader understand a new method quickly by asking what its function family, loss and penalty are.

Finding structure without labels

Unsupervised learning

The ninth key idea concerns problems with no output to predict. In unsupervised learning, the task is to describe the structure of the inputs: which cases are similar, which variables move together, which combinations of values occur often. The book notes a basic difficulty. Without a known answer there is no direct measure of success, so judging results depends heavily on the purpose and on judgement.

The chapter covers association rules, which look for combinations of items that occur together, as in shopping baskets; clustering methods such as K-means and hierarchical clustering, which group cases; and methods for reducing dimension, such as principal components, which find the directions of greatest variation. It also covers self-organising maps, principal curves, independent component analysis, spectral clustering and multidimensional scaling.

One clever device is to turn an unsupervised problem into a supervised one. Generate a reference sample of artificial data spread uniformly or according to some simple distribution, label the real data as one class and the reference as another, and train a classifier to tell them apart. Regions where the classifier is confident that data are real are regions of real structure. This idea shows the book's habit of reusing tools across tasks.

More variables than cases

The second edition added a chapter on problems in which the number of input variables far exceeds the number of observations, as in genomics, where thousands of genes may be measured for a few dozen patients. In this setting, least squares cannot even be computed, and overfitting is the default. Regularisation becomes essential rather than optional. The chapter discusses shrunken centroid methods, regularised discriminant analysis, the lasso and the problem of controlling false discoveries when thousands of hypotheses are tested at once. This material reflects the authors' own work in genomic data analysis and anticipates the field of high-dimensional statistics that grew rapidly in the following decade.

What the second edition added

New chapters

The second edition, published eight years after the first, reflects how quickly the field moved. Besides random forests and high-dimensional problems, already discussed, it added a chapter on ensemble learning that treats boosting, bagging and random forests as members of one family and introduces ideas such as learning a sparse combination of many base models with the lasso. It also added a chapter on undirected graphical models, which represent the pattern of dependence among many variables as a network. The graphical lasso, developed by Friedman, Hastie and Tibshirani, estimates such a network by applying a lasso penalty to the inverse of the covariance matrix, so that most pairs of variables are judged conditionally independent.

Existing chapters were also extended. The material on linear methods gained the least angle regression algorithm and the paths of lasso solutions. Discussion of model assessment was sharpened, including the warning about selecting variables before cross-validation. The unsupervised chapter gained spectral clustering, non-negative matrix factorisation and other methods that had become popular. Many figures were redrawn or added.

Data sets as teachers

One feature of both editions deserves mention because it shapes how the book teaches. The authors use a recurring set of data sets throughout: simulated two-class problems drawn as coloured points, data on prostate cancer patients, data on spam email, handwritten digits, gene expression measurements and others. Because the same data appear in different chapters, the reader can see how different methods behave on the same problem. This gives the comparisons a concreteness that abstract theory alone would lack. A good habit while reading is to follow one data set across chapters and keep notes on how each method performs and why.

The authors also make these data sets available, so that readers can repeat the analyses. Doing so is one of the best ways to learn from the book, since it turns each figure into an experiment the reader can vary. Change the amount of training data, the penalty, or the depth of the trees, and watch how the result moves.

The tradition around it

What came before

The book stands on a long statistical tradition: least squares from the early nineteenth century, discriminant analysis from Ronald Fisher in the 1930s, nonparametric smoothing from the mid twentieth century, and the computer-intensive methods of the 1970s and 1980s, such as the bootstrap and cross-validation. It also absorbs ideas from pattern recognition, a field that had grown up in engineering, and from machine learning in computer science, including perceptrons, neural networks, decision tree learning and computational learning theory.

Leo Breiman's essay on the two cultures of statistical modelling, published in 2001, describes the same moment from another angle. Breiman argued that statistics had been too attached to data models with interpretable parameters and too little interested in algorithmic models judged by predictive accuracy. This book can be read as a bridge between the two cultures: written by statisticians, respectful of models and inference, but fully engaged with algorithmic prediction.

What came after

After 2009, the field moved quickly. Deep learning transformed vision, speech and language from around 2012. Gradient boosting libraries made boosted trees the default for tabular prediction. Sparse methods and high-dimensional theory matured, partly in the authors' own later books. Interest grew in interpretability, fairness, causal inference and uncertainty quantification. The book remains the standard reference for the statistical core of machine learning, even as the frontier moved to areas it covers only lightly.

Its neighbours on this shelf

Pattern Recognition and Machine Learning by Christopher Bishop is the closest neighbour and makes an instructive contrast. Bishop writes from a Bayesian point of view, treating parameters as uncertain quantities with probability distributions, while this book is mainly frequentist, judging methods by their performance over repeated samples. Reading both shows the same methods seen from two sides. Information Theory, Inference, and Learning Algorithms by David MacKay adds the link between learning and compression, and a third view of model complexity through Bayesian evidence.

Causality by Judea Pearl marks a boundary this book does not cross. Everything here concerns prediction, the association between inputs and outputs in data like the training set. Pearl asks what happens when we intervene. A model can predict very well and still say nothing about what would happen if we changed an input. Perceptrons by Minsky and Papert and Parallel Distributed Processing by Rumelhart, McClelland and colleagues give the history of the neural network ideas treated here in statistical form. Artificial Intelligence: A Modern Approach places learning inside a broader account of intelligent agents, and Reinforcement Learning by Sutton and Barto covers learning from rewards, which this book does not treat.

Questions and criticisms

What has aged

The clearest change since the second edition is deep learning. Modern networks with millions or billions of parameters are trained to fit their training data almost perfectly and still generalise well. This seemed to contradict the classical picture of a U-shaped test error curve. Work on the phenomenon called double descent showed that test error can fall again once models become large enough to interpolate the data, especially with implicit regularisation from the training algorithm. The bias and variance framework is not wrong, but the simple picture of a single best complexity does not cover these regimes. Hastie and Tibshirani themselves have contributed to research on this question.

The coverage of neural networks is therefore thin by current standards, and there is little on convolutional or recurrent architectures, representation learning or the training of large models. Topics such as online learning, reinforcement learning and probabilistic programming are absent or brief. A reader should not expect this book to teach modern deep learning.

Fair objections

Some readers find the book uneven in difficulty, with passages of easy explanation followed by dense derivations with steps omitted. The exercises vary greatly in difficulty and have no official solutions. The book's frequentist stance means that Bayesian approaches get less space than their importance warrants, and readers who want a full probabilistic treatment should turn to Bishop or MacKay. The authors' natural enthusiasm for methods they developed, such as the lasso, additive models and boosting, gives those methods prominent places, though the comparisons offered are generally fair.

A deeper objection is that the book says little about where data come from. Selection bias, measurement error, shifts between training and deployment populations, and the causal meaning of fitted relationships are treated briefly or not at all. These are often the main sources of failure in practice, and a model that validates well in a held-out sample can still fail if the future differs from the past. This is not a flaw in what the book does, but it marks a boundary that readers should remember.

What has held up

Much has held up remarkably well. Regularisation, cross-validation, ensembles of trees and gradient boosting remain the working core of applied machine learning outside perception and language. The habit of thinking in terms of loss, penalty and validation is as relevant to fitting a large network as to fitting a linear model. The warnings about information leakage and selection bias in validation remain necessary. Many practitioners still keep this book within reach as a reference precisely because it explains why methods work, not only how to call them.

Why it is on this shelf

This book sits in the artificial intelligence bay because most of what is called artificial intelligence in daily use is statistical learning of the kind described here. Credit scores, fraud alerts, demand forecasts, crop yield predictions and the ranking of search results are built from regularised regressions, trees and boosted ensembles far more often than from anything exotic. To understand those systems, and to know when to trust them, one needs the ideas in this book.

For a reader of economics, the book is a bridge between econometrics and machine learning. Economists learned regression first as a tool for estimating parameters with meaning; this book treats it as a tool for prediction. Both uses are valid, and confusing them causes trouble. The book makes the difference clear and shows what each use requires. For a reader of science, it gives the discipline of honest validation, which protects against the most common form of self-deception in data analysis: believing that a pattern found in a sample will hold outside it.

For a reader of technology, the book offers a kind of grammar. New methods appear every year, often with new names. A reader who has absorbed the frame of function family, loss, penalty and validation can place most of them quickly and see what is truly new. That is worth more than familiarity with any single tool.

For a reader of Vedanta and Jyotish, the connection is indirect but real. Both traditions involve reading patterns from limited evidence and making predictions about particular cases. The book's central caution, that a rule which fits past cases well may fit them because it has learned their noise, applies to any system of interpretation. Its remedy, judging a rule only on cases it was not built from, is a discipline any careful reader of signs can adopt. We keep it on the shelf as a teacher of that discipline as much as of its methods.

How to read it

Before you begin

Check your preparation. You will need comfort with matrices, derivatives and probability distributions, and a working knowledge of linear regression. If any of these is shaky, read An Introduction to Statistical Learning first. It covers many of the same ideas at a gentler level, with practical exercises, and was written by two of the same authors with that purpose in mind. Many readers use it as a first pass and this book as the second.

First pass

Read the overview of supervised learning slowly. It introduces the framework, the contrast between linear models and nearest neighbours, the curse of dimensionality and the bias and variance trade-off. Then read the chapter on linear methods for regression, concentrating on least squares, subset selection, ridge regression and the lasso. Draw the geometric picture of the ridge and lasso penalties yourself until it makes sense. Then go straight to the chapter on model assessment and selection, which is the most useful single chapter for practice.

After those three, read the chapters on trees, boosting and random forests. These are the methods most likely to be useful in practice, and they reward the bias and variance thinking built up earlier. At a pace of a section or two a day, this first pass takes about six to eight weeks. Skim the derivations on first reading and focus on the figures and their discussion.

What to skip at first

On a first pass, the chapters on kernel smoothing, the material on reproducing kernel Hilbert spaces, the more technical parts of the chapter on model inference and averaging, and most of the unsupervised learning chapter can be skimmed. The neural network chapter is short and can be read quickly for its framing, but a modern course is a better source for that subject. The high-dimensional chapter is valuable if your work involves many variables and few cases and can otherwise wait.

Second pass with a pencil

On a second pass, work through the derivations in the linear methods chapter, including the singular value decomposition view of ridge regression and the computation of effective degrees of freedom. Derive the connection between AdaBoost and exponential loss. Work the support vector classifier as a penalised hinge loss. Choose a few exercises at the end of chapters and do them fully. The most valuable practice of all is to implement a few methods yourself on real data: a lasso path, a cross-validated tree, a small gradient boosting loop. Watching training and validation error move as you change one setting teaches more than any page.

Keep a notebook of the book's recurring figures redrawn in your own hand: the error curves, the penalty shapes, the coefficient paths. Redrawing a figure from memory a week later is a reliable test of whether its idea has stayed with you. If you cannot redraw it, return to the section and read the discussion around it again.

What next from this shelf

Read Pattern Recognition and Machine Learning by Bishop next for the Bayesian view of the same territory. Then read Information Theory, Inference, and Learning Algorithms by MacKay for the link between learning and compression. Then read Causality by Pearl, to see clearly what prediction cannot tell you. For learning from interaction rather than from fixed data, read Reinforcement Learning by Sutton and Barto.

Questions to carry

  • In your current problem, what function family, loss and penalty are you using, even if you have not named them?
  • How would your model's predictions change if it were refitted on a different sample from the same population?
  • Is your validation data truly untouched by every step of model building, including the choice of variables?
  • Which inputs would the lasso drop from your model, and do you have a reason to keep them anyway?
  • When does accepting bias in an estimate make it more useful, and when should bias be avoided at all costs?
  • Why does averaging many unstable trees help, and in what situation would it not help?
  • How do boosting and bagging differ in what kind of error they mainly reduce?
  • What structure in your data lets you escape the curse of dimensionality?
  • If two methods give similar validation error, which would you prefer, and why?
  • What would make a model that validates well today fail next year?
  • When you interpret a coefficient or an importance score, are you describing prediction or claiming cause?
  • How should the purpose of an unsupervised analysis shape the choice of method and the judgement of results?
  • What would you need to know before trusting a model built on many more variables than observations?

Words to know

  • Supervised learning: learning a mapping from inputs to a known output using labelled examples.
  • Unsupervised learning: finding structure in inputs when no output is given.
  • Loss function: a measure of the cost of a wrong prediction, such as squared error.
  • Bias: the systematic difference between a method's average prediction and the true value.
  • Variance: the spread of a method's predictions across different training samples.
  • Overfitting: fitting noise in the training data so that performance on new data suffers.
  • Curse of dimensionality: the sparseness of data in many dimensions, which makes local methods fail.
  • Regularisation: adding a penalty on complexity to the fitting criterion in order to reduce variance.
  • Ridge regression: least squares with a penalty on the sum of squared coefficients.
  • Lasso: least squares with a penalty on the sum of absolute coefficients, which sets some to zero.
  • Elastic net: a penalty combining ridge and lasso, useful when inputs are correlated.
  • Basis expansion: transforming inputs into new functions so that a linear method can fit curves.
  • Spline: a function built from polynomial pieces joined smoothly at points called knots.
  • Kernel: a weighting or similarity function used in local fitting and in methods like support vector machines.
  • Effective degrees of freedom: a measure of a fitted model's complexity that applies across different kinds of method.
  • Cross-validation: estimating prediction error by repeatedly holding out part of the data for testing.
  • Bootstrap: resampling the data with replacement to estimate uncertainty or error.
  • Decision tree: a model that splits the input space into rectangles by a sequence of single-variable questions.
  • Bagging: averaging models fitted to bootstrap samples to reduce variance.
  • Random forest: bagged trees in which each split considers only a random subset of inputs.
  • Boosting: building a model in stages, each stage correcting the errors of the previous ones.
  • Gradient boosting: boosting framed as descent on a loss function, with each tree fitted to the negative gradient.
  • Hinge loss: the loss underlying support vector machines, zero for cases classified with a sufficient margin.
  • Principal components: directions in the data that capture the most variation, used to reduce dimension.

A note on this edition

This is a study edition written for this shelf in our own words. It explains the ideas and context of The Elements of Statistical Learning but does not reproduce its text, figures or exercises. The book itself is in copyright. Its authors have made the second edition available to read from their own website, and it is also worth having in print from a library or bookshop, where its colour figures can be studied at leisure.

More from “Artificial intelligence”

The whole section →