


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



















The MIT Press Cambridge, Massachusetts London, England
We are drowning in information and starving for knowledge. — John Naisbitt.
We are entering the era of big data. For example, there are about 1 trillion web pages 1 ; one hour of video is uploaded to YouTube every second, amounting to 10 years of content every day^2 ; the genomes of 1000s of people, each of which has a length of 3. 8 × 10 9 base pairs, have been sequenced by various labs; Walmart handles more than 1M transactions per hour and has databases containing more than 2.5 petabytes ( 2. 5 × 10 15 ) of information (Cukier 2010); and so on. This deluge of data calls for automated methods of data analysis, which is what machine learning provides. In particular, we define machine learning as a set of methods that can automatically detect patterns in data, and then use the uncovered patterns to predict future data, or to perform other kinds of decision making under uncertainty (such as planning how to collect more data!). This books adopts the view that the best way to solve such problems is to use the tools of probability theory. Probability theory can be applied to any problem involving uncertainty. In machine learning, uncertainty comes in many forms: what is the best prediction about the future given some past data? what is the best model to explain some data? what measurement should I perform next? etc. The probabilistic approach to machine learning is closely related to the field of statistics, but diers slightly in terms of its emphasis and terminology 3. We will describe a wide variety of probabilistic models, suitable for a wide variety of data and tasks. We will also describe a wide variety of algorithms for learning and using such models. The goal is not to develop a cook book of ad hoc techiques, but instead to present a unified view of the field through the lens of probabilistic modeling and inference. Although we will pay attention to computational eciency, details on how to scale these methods to truly massive datasets are better described in other books, such as (Rajaraman and Ullman 2011; Bekkerman et al. 2011).
1.2. Supervised learning 3
(a) (b)
Figure 1.1 Left: Some labeled training examples of colored shapes, along with 3 unlabeled test cases. Right: Representing the training data as an N × D design matrix. Row i represents the feature vector x (^) i. The last column is the label, y (^) i ∈ { 0 , 1 }. Based on a figure by Leslie Kaelbling.
We begin our investigation of machine learning by discussing supervised learning, which is the form of ML most widely used in practice.
In this section, we discuss classification. Here the goal is to learn a mapping from inputs x to outputs y, where y ∈ { 1 ,... , C}, with C being the number of classes. If C = 2, this is called binary classification (in which case we often assume y ∈ { 0 , 1 }); if C > 2 , this is called multiclass classification. If the class labels are not mutually exclusive (e.g., somebody may be classified as tall and strong), we call it multi-label classification , but this is best viewed as predicting multiple related binary class labels (a so-called multiple output model ). When we use the term “classification”, we will mean multiclass classification with a single output, unless we state otherwise. One way to formalize the problem is as function approximation. We assume y = f (x) for some unknown function f , and the goal of learning is to estimate the function f given a labeled training set, and then to make predictions using ˆy = fˆ (x). (We use the hat symbol to denote an estimate.) Our main goal is to make predictions on novel inputs, meaning ones that we have not seen before (this is called generalization ), since predicting the response on the training set is easy (we can just look up the answer).
1.2.1.1 Example
As a simple toy example of classification, consider the problem illustrated in Figure 1.1(a). We have two classes of object which correspond to labels 0 and 1. The inputs are colored shapes. These have been described by a set of D features or attributes, which are stored in an N × D design matrix X, shown in Figure 1.1(b). The input features x can be discrete, continuous or a combination of the two. In addition to the inputs, we have a vector of training labels y. In Figure 1.1, the test cases are a blue crescent, a yellow circle and a blue arrow. None of these have been seen before. Thus we are required to generalize beyond the training set. A
4 Chapter 1. Introduction
reasonable guess is that blue crescent should be y = 1, since all blue shapes are labeled 1 in the training set. The yellow circle is harder to classify, since some yellow things are labeled y = 1 and some are labeled y = 0, and some circles are labeled y = 1 and some y = 0. Consequently it is not clear what the right label should be in the case of the yellow circle. Similarly, the correct label for the blue arrow is unclear.
1.2.1.2 The need for probabilistic predictions
To handle ambiguous cases, such as the yellow circle above, it is desirable to return a probability. The reader is assumed to already have some familiarity with basic concepts in probability. If not, please consult Chapter 2 for a refresher, if necessary. We will denote the probability distribution over possible labels, given the input vector x and training set D by p(y|x, D). In general, this represents a vector of length C. (If there are just two classes, it is sucient to return the single number p(y = 1|x, D), since p(y = 1|x, D) + p(y = 0 |x, D) = 1.) In our notation, we make explicit that the probability is conditional on the test input x, as well as the training set D, by putting these terms on the right hand side of the conditioning bar |. We are also implicitly conditioning on the form of model that we use to make predictions. When choosing between dierent models, we will make this assumption explicit by writing p(y|x, D, M ), where M denotes the model. However, if the model is clear from context, we will drop M from our notation for brevity. Given a probabilistic output, we can always compute our “best guess” as to the “true label” using
ˆy = fˆ (x) = C argmax c=
p(y = c|x, D) (1.1)
This corresponds to the most probable class label, and is called the mode of the distribution p(y|x, D); it is also known as a MAP estimate (MAP stands for maximum a posteriori ). Using the most probable label makes intuitive sense, but we will give a more formal justification for this procedure in Section 5.7. Now consider a case such as the yellow circle, where p(ˆy|x, D) is far from 1.0. In such a case we are not very confident of our answer, so it might be better to say “I don’t know” instead of returning an answer that we don’t really trust. This is particularly important in domains such as medicine and finance where we may be risk averse, as we explain in Section 5.7. Another application where it is important to assess risk is when playing TV game shows, such as Jeopardy. In this game, contestants have to solve various word puzzles and answer a variety of trivia questions, but if they answer incorrectly, they lose money. In 2011, IBM unveiled a computer system called Watson which beat the top human Jeopardy champion. Watson uses a variety of interesting techniques (Ferrucci et al. 2010), but the most pertinent one for our present purposes is that it contains a module that estimates how confident it is of its answer. The system only chooses to “buzz in” its answer if suciently confident it is correct. Similarly, Google has a system known as SmartASS (ad selection system) that predicts the probability you will click on an ad based on your search history and other user and ad-specific features (Metz 2010). This probability is known as the click-through rate or CTR , and can be used to maximize expected profit. We will discuss some of the basic principles behind systems such as SmartASS later in this book.
6 Chapter 1. Introduction
(a) (b) (c)
Figure 1.3 Three types of iris flowers: setosa, versicolor and virginica. Source: http://www.statlab.u ni-heidelberg.de/data/iris/. Used with kind permission of Dennis Kramb and SIGNA.
sepal length
sepal length
sepal width
petal length
petal width
sepal width petal length petal width
Figure 1.4 Visualization of the Iris data as a pairwise scatter plot. The diagonal plots the marginal histograms of the 4 features. The o diagonals contain scatterplots of all possible pairs of features. Red circle = setosa, green diamond = versicolor, blue star = virginica. Figure generated by fisheririsDemo.
Classifying flowers
Figure 1.3 gives another example of classification, due to the statistician Ronald Fisher. The goal is to learn to distinguish three dierent kinds of iris flower, called setosa, versicolor and virginica. Fortunately, rather than working directly with images, a botanist has already extracted 4 useful features or characteristics: sepal length and width, and petal length and width. (Such feature extraction is an important, but dicult, task. Most machine learning methods use features chosen by some human. Later we will discuss some methods that can learn good features from the data.) If we make a scatter plot of the iris data, as in Figure 1.4, we see that it is easy to distinguish setosas (red circles) from the other two classes by just checking if their petal length
1.2. Supervised learning 7
true class = 7 true class = 2 true class = 1
true class = 0 true class = 4 true class = 1
true class = 4 true class = 9 true class = 5
(a)
true class = 7 true class = 2 true class = 1
true class = 0 true class = 4 true class = 1
true class = 4 true class = 9 true class = 5
(b)
Figure 1.5 (a) First 9 test MNIST gray-scale images. (b) Same as (a), but with the features permuted randomly. Classification performance is identical on both versions of the data (assuming the training data is permuted in an identical way). Figure generated by shuffledDigitsDemo.
or width is below some threshold. However, distinguishing versicolor from virginica is slightly harder; any decision will need to be based on at least two features. (It is always a good idea to perform exploratory data analysis , such as plotting the data, before applying a machine learning method.)
Image classification and handwriting recognition
Now consider the harder problem of classifying images directly, where a human has not pre- processed the data. We might want to classify the image as a whole, e.g., is it an indoors or outdoors scene? is it a horizontal or vertical photo? does it contain a dog or not? This is called image classification. In the special case that the images consist of isolated handwritten letters and digits, for example, in a postal or ZIP code on a letter, we can use classification to perform handwriting recognition. A standard dataset used in this area is known as MNIST , which stands for “Modified National Institute of Standards” 5. (The term “modified” is used because the images have been preprocessed to ensure the digits are mostly in the center of the image.) This dataset contains 60,000 training images and 10,000 test images of the digits 0 to 9, as written by various people. The images are size 28 × 28 and have grayscale values in the range 0 : 255. See Figure 1.5(a) for some example images. Many generic classification methods ignore any structure in the input features, such as spatial layout. Consequently, they can also just as easily handle data that looks like Figure 1.5(b), which is the same data except we have randomly permuted the order of all the features. (You will verify this in Exercise 1.1.) This flexibility is both a blessing (since the methods are general purpose) and a curse (since the methods ignore an obviously useful source of information). We will discuss methods for exploiting structure in the input features later in the book.
1.3. Unsupervised learning 9
− (^100 5 10 15 )
− 5
0
5
10
15 degree 1
(a)
− (^100 5 10 15 )
− 5
0
5
10
15 degree 2
(b)
Figure 1.7 (a) Linear regression on some 1d data. (b) Same data with polynomial regression (degree 2). Figure generated by linregPolyVsDegree.
Here are some examples of real-world regression problems.
We now consider unsupervised learning , where we are just given output data, without any inputs. The goal is to discover “interesting structure” in the data; this is sometimes called knowledge discovery. Unlike supervised learning, we are not told what the desired output is for each input. Instead, we will formalize our task as one of density estimation , that is, we want to build models of the form p(x (^) i |θ). There are two dierences from the supervised case. First, we have written p(x (^) i |θ) instead of p(y (^) i |x (^) i , θ); that is, supervised learning is conditional density estimation, whereas unsupervised learning is unconditional density estimation. Second, x (^) i is a vector of features, so we need to create multivariate probability models. By contrast, in supervised learning, y (^) i is usually just a single variable that we are trying to predict. This means that for most supervised learning problems, we can use univariate probability models (with input-dependent parameters), which significantly simplifies the problem. (We will discuss multi-output classification in Chapter 19, where we will see that it also involves multivariate probability models.) Unsupervised learning is arguably more typical of human and animal learning. It is also more widely applicable than supervised learning, since it does not require a human expert to
10 Chapter 1. Introduction
(^8055 60 65 70 75 )
100
120
140
160
180
200
220
240
260
280
height
weight
(a)
(^8055 60 65 70 75 )
100
120
140
160
180
200
220
240
260
280
height
weight
K=
(b)
Figure 1.8 (a) The height and weight of some people. (b) A possible clustering using K = 2 clusters. Figure generated by kmeansHeightWeight.
manually label the data. Labeled data is not only expensive to acquire 6 , but it also contains relatively little information, certainly not enough to reliably estimate the parameters of complex models. Geo Hinton, who is a famous professor of ML at the University of Toronto, has said:
When we’re learning to see, nobody’s telling us what the right answers are — we just look. Every so often, your mother says “that’s a dog”, but that’s very little information. You’d be lucky if you got a few bits of information — even one bit per second — that way. The brain’s visual system has 1014 neural connections. And you only live for 10 9 seconds. So it’s no use learning one bit per second. You need more like 10 5 bits per second. And there’s only one place you can get that much information: from the input itself. — Georey Hinton, 1996 (quoted in (Gorder 2006)). Below we describe some canonical examples of unsupervised learning.
As a canonical example of unsupervised learning, consider the problem of clustering data into groups. For example, Figure 1.8(a) plots some 2d data, representing the height and weight of a group of 210 people. It seems that there might be various clusters, or subgroups, although it is not clear how many. Let K denote the number of clusters. Our first goal is to estimate the distribution over the number of clusters, p(K|D); this tells us if there are subpopulations within the data. For simplicity, we often approximate the distribution p(K|D) by its mode, K ∗^ = arg max (^) K p(K|D). In the supervised case, we were told that there are two classes (male and female), but in the unsupervised case, we are free to choose as many or few clusters as we like. Picking a model of the “right” complexity is called model selection, and will be discussed in detail below. Our second goal is to estimate which cluster each point belongs to. Let z (^) i ∈ { 1 ,... , K} represent the cluster to which data point i is assigned. (z (^) i is an example of a hidden or
12 Chapter 1. Introduction
(a) (b)
Figure 1.10 a) 25 randomly chosen 64 × 64 pixel images from the Olivetti face database. (b) The mean and the first three principal component basis vectors (eigenfaces). Figure generated by pcaImageDemo.
When used as input to other statistical models, such low dimensional representations often result in better predictive accuracy, because they focus on the “essence” of the object, filtering out inessential features. Also, low dimensional representations are useful for enabling fast nearest neighbor searches and two dimensional projections are very useful for visualizing high dimensional data. The most common approach to dimensionality reduction is called principal components analysis or PCA. This can be thought of as an unsupervised version of (multi-output) linear regression, where we observe the high-dimensional response y, but not the low-dimensional “cause” z. Thus the model has the form z → y; we have to “invert the arrow”, and infer the latent low-dimensional z from the observed high-dimensional y. See Section 12.1 for details. Dimensionality reduction, and PCA in particular, has been applied in many dierent areas. Some examples include the following:
1.3. Unsupervised learning (^) lambda=7.00, nedges=18 13
Figure 1.11 A sparse undirected Gaussian graphical model learned using graphical lasso (Section 26.7.2) applied to some flow cytometry data (from (Sachs et al. 2005)), which measures the phosphorylation status of 11 proteins. Figure generated by ggmLassoDemo.
Sometimes we measure a set of correlated variables, and we would like to discover which ones are most correlated with which others. This can be represented by a graph G, in which nodes represent variables, and edges represent direct dependence between variables (we will make this precise in Chapter 10, when we discuss graphical models). We can then learn this graph structure from data, i.e., we compute Gˆ = argmax p(G|D). As with unsupervised learning in general, there are two main applications for learning sparse graphs: to discover new knowledge, and to get better joint probability density estimators. We now give somes example of each.
1.3. Unsupervised learning 15
XVHUV
PRYLHV
" " " "
Figure 1.13 Example of movie-rating data. Training data is in red, test data is denoted by ?, empty cells are unknown.
(say an integer between 1 and 5, where 1 is dislike and 5 is like) by user u of movie m. Note that most of the entries in X will be missing or unknown, since most users will not have rated most movies. Hence we only observe a tiny subset of the X matrix, and we want to predict a dierent subset. In particular, for any given user u, we might want to predict which of the unrated movies he/she is most likely to want to watch. In order to encourage research in this area, the DVD rental company Netflix created a com- petition, launched in 2006, with a $1M USD prize (see http://netflixprize.com/). In particular, they provided a large matrix of ratings, on a scale of 1 to 5, for ∼ 18 k movies created by ∼ 500 k users. The full matrix would have ∼ 9 × 10 9 entries, but only about 1% of the entries are observed, so the matrix is extremely sparse. A subset of these are used for training, and the rest for testing, as shown in Figure 1.13. The goal of the competition was to predict more accurately than Netflix’s existing system. On 21 September 2009, the prize was awarded to a team of researchers known as “BellKor’s Pragmatic Chaos”. Section 27.6.2 discusses some of their methodology. Further details on the teams and their methods can be found at http://www.netflixprize.com/community/viewtopic.php?id=1537.
1.3.4.3 Market basket analysis
In commercial data mining, there is much interest in a task called market basket analysis. The data consists of a (typically very large but sparse) binary matrix, where each column represents an item or product, and each row represents a transaction. We set x (^) ij = 1 if item j was purchased on the i’th transaction. Many items are purchased together (e.g., bread and butter), so there will be correlations amongst the bits. Given a new partially observed bit vector, representing a subset of items that the consumer has bought, the goal is to predict which other bits are likely to turn on, representing other items the consumer might be likely to buy. (Unlike collaborative filtering, we often assume there is no missing data in the training data, since we know the past shopping behavior of each customer.) This task arises in other domains besides modeling purchasing patterns. For example, similar techniques can be used to model dependencies between files in complex software systems. In this case, the task is to predict, given a subset of files that have been changed, which other ones need to be updated to ensure consistency (see e.g., (Hu et al. 2010)). It is common to solve such tasks using frequent itemset mining , which create association rules (see e.g., (Hastie et al. 2009, sec 14.2) for details). Alternatively, we can adopt a probabilistic approach, and fit a joint density model p(x 1 ,... , x (^) D ) to the bit vectors, see e.g., (Hu et al.
16 Chapter 1. Introduction
(a) (b)
Figure 1.14 (a) Illustration of a K-nearest neighbors classifier in 2d for K = 3. The 3 nearest neighbors of test point x 1 have labels 1, 1 and 0, so we predict p(y = 1|x 1 , D, K = 3) = 2/ 3. The 3 nearest neighbors of test point x 2 have labels 0, 0, and 0, so we predict p(y = 1|x 2 , D, K = 3) = 0/ 3. (b) Illustration of the Voronoi tesselation induced by 1-NN. Based on Figure 4.13 of (Duda et al. 2001). Figure generated by knnVoronoi.
2010). Such models often have better predictive acccuracy than association rules, although they may be less interpretible. This is typical of the dierence between data mining and machine learning: in data mining, there is more emphasis on interpretable models, whereas in machine learning, there is more emphasis on accurate models.
In this Section, we provide an introduction to some key ideas in machine learning. We will expand on these concepts later in the book, but we introduce them briefly here, to give a flavor of things to come.
In this book, we will be focussing on probabilistic models of the form p(y|x) or p(x), depending on whether we are interested in supervised or unsupervised learning respectively. There are many ways to define such models, but the most important distinction is this: does the model have a fixed number of parameters, or does the number of parameters grow with the amount of training data? The former is called a parametric model , and the latter is called a non- parametric model. Parametric models have the advantage of often being faster to use, but the disadvantage of making stronger assumptions about the nature of the data distributions. Non- parametric models are more flexible, but often computationally intractable for large datasets. We will give examples of both kinds of models in the sections below. We focus on supervised learning for simplicity, although much of our discussion also applies to unsupervised learning.
A simple example of a non-parametric classifier is the K nearest neighbor ( KNN ) classifier. This simply “looks at” the K points in the training set that are nearest to the test input x,
18 Chapter 1. Introduction
s 1
1
0
(a)
(^00) 0.2 0.4 0.6 0.8 1
1
Fraction of data in neighborhood
Edge length of cube d=
d=
d=
d= d=
(b)
Figure 1.16 Illustration of the curse of dimensionality. (a) We embed a small cube of side s inside a larger unit cube. (b) We plot the edge length of a cube needed to cover a given volume of the unit cube as a function of the number of dimensions. Based on Figure 2.6 from (Hastie et al. 2009). Figure generated by curseDimensionality.
distance metric to use is Euclidean distance (which limits the applicability of the technique to data which is real-valued), although other metrics can be used. Figure 1.15 gives an example of the method in action, where the input is two dimensional, we have three classes, and K = 10. (We discuss the eect of K below.) Panel (a) plots the training data. Panel (b) plots p(y = 1|x, D) where x is evaluated on a grid of points. Panel (c) plots p(y = 2|x, D). We do not need to plot p(y = 3|x, D), since probabilities sum to one. Panel (d) plots the MAP estimate ˆy(x) = argmax (^) c (y = c|x, D). A KNN classifier with K = 1 induces a Voronoi tessellation of the points (see Figure 1.14(b)). This is a partition of space which associates a region V (x (^) i ) with each point x (^) i in such a way that all points in V (x (^) i ) are closer to x (^) i than to any other point. Within each cell, the predicted label is the label of the corresponding training point.
The KNN classifier is simple and can work quite well, provided it is given a good distance metric and has enough labeled training data. In fact, it can be shown that the KNN classifier can come within a factor of 2 of the best possible performance if N → ∞ (Cover and Hart 1967). However, the main problem with KNN classifiers is that they do not work well with high dimensional inputs. The poor performance in high dimensional settings is due to the curse of dimensionality. To explain the curse, we give some examples from (Hastie et al. 2009, p22). Consider applying a KNN classifier to data where the inputs are uniformly distributed in the D-dimensional unit cube. Suppose we estimate the density of class labels around a test point x by “growing” a hyper-cube around x until it contains a desired fraction f of the data points. The expected edge length of this cube will be e (^) D (f ) = f 1 /D^. If D = 10, and we want to base our estimate on 10%
1.4. Some basic concepts in machine learning 19
−^03 − 2 − 1 0 1 2 3
0.4^ PDF
(a) (b)
Figure 1.17 (a) A Gaussian pdf with mean 0 and variance 1. Figure generated by gaussPlotDemo. (b) Visualization of the conditional density model p(y|x, θ) = N (y|w 0 + w 1 x, σ 2 ). The density falls o exponentially fast as we move away from the regression line. Figure generated by linregWedgeDemo2.
of the data, we have e 10 (0.1) = 0. 8 , so we need to extend the cube 80% along each dimension around x. Even if we only use 1% of the data, we find e 10 (0.01) = 0. 63 : see Figure 1.16. Since the entire range of the data is only 1 along each dimension, we see that the method is no longer very local, despite the name “nearest neighbor”. The trouble with looking at neighbors that are so far away is that they may not be good predictors about the behavior of the input-output function at a given point.
The main way to combat the curse of dimensionality is to make some assumptions about the nature of the data distribution (either p(y|x) for a supervised problem or p(x) for an unsupervised problem). These assumptions, known as inductive bias , are often embodied in the form of a parametric model , which is a statistical model with a fixed number of parameters. Below we briefly describe two widely used examples; we will revisit these and other models in much greater depth later in the book.
One of the most widely used models for regression is known as linear regression. This asserts that the response is a linear function of the inputs. This can be written as follows:
y(x) = w T^ x + =
j=
w (^) j x (^) j + (1.4)
where w T^ x represents the inner or scalar product between the input vector x and the model’s weight vector w 7 , and is the residual error between our linear predictions and the true response.