Docsity

Machine Learning: Linear Regression, SVD, and Discriminant Analysis, Study notes of Data Analysis & Statistical Methods

Toggle sidebar
bg1
Stat 648 Outline
Steve Vardeman
Iowa State University
May 10, 2009
Abstract
This outline summarizes the main p oints of lectures based on the book
The Elements of Statistical Learning by Hastie, Tibshirani, an d Friedman.
Some of the later material here bene…ts from Izenman’s Modern Multi-
variate Statistical Techniques.
Contents
1 Introduction (Ch 1 and Ch 2 of HTF) 4
1.1 Some Very Simple Probability Theory and Decision Theory and
Prediction Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2 Two Conceptually Simple Ways One Might Approximate a Con-
ditional Mean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2.1 Nearest Neighbor Rules . . . . . . . . . . . . . . . . . . . 6
1.2.2 Rules Based on a Linear Assumption About the Form of
the Conditional Mean . . . . . . . . . . . . . . . . . . . . 6
1.3 The Curse of Dimensionality . . . . . . . . . . . . . . . . . . . . 7
1.4 Variance-Bias Considerations in Prediction . . . . . . . . . . . . 8
1.5 Some Fancier Ways One Might Approximate a Conditional Mean 9
1.5.1 (Non-)Linear Regression Methods (Least Squares Fitting) 9
1.5.2 Methods Based on Local Smoothing/Averaging . . . . . . 10
1.6 Complexity, Fit, and Choice of Tuning Parameters . . . . . . . . 11
2 Linear Methods (Ch 3 of HTF) 11
2.1 The Gram-Schmidt Process and the QR Decomp osition . . . . . 12
2.2 The Singular Value Decomposition of a Full Rank X. . . . . . . 14
2.3 Ridge Regression and the Lasso and Some Generalizations Thereof 16
2.3.1 Ridge Regression . . . . . . . . . . . . . . . . . . . . . . . 16
2.3.2 The Lasso and Generalizations . . . . . . . . . . . . . . . 17
2.4 Two Methods With Derived Input Variables . . . . . . . . . . . . 19
Cour se devel opm ent supp ort ed by NSF g rant DM S #0 5023 47 EM SW2 1-RTG awa rded to
the De partm ent of S tatis tics, Iowa St ate Un ivers ity.
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61

Partial preview of the text

Download Machine Learning: Linear Regression, SVD, and Discriminant Analysis and more Study notes Data Analysis & Statistical Methods in PDF only on Docsity!

Stat 648 Outline

Steve Vardeman

Iowa State University

May 10, 2009

Abstract This outline summarizes the main points of lectures based on the book The Elements of Statistical Learning by Hastie, Tibshirani, and Friedman. Some of the later material here beneÖts from Izenmanís Modern Multi- variate Statistical Techniques.

Contents

1 Introduction (Ch 1 and Ch 2 of HTF) 4 1.1 Some Very Simple Probability Theory and Decision Theory and Prediction Rules........................... 5 1.2 Two Conceptually Simple Ways One Might Approximate a Con- ditional Mean............................. 6 1.2.1 Nearest Neighbor Rules................... 6 1.2.2 Rules Based on a Linear Assumption About the Form of the Conditional Mean.................... 6 1.3 The Curse of Dimensionality.................... 7 1.4 Variance-Bias Considerations in Prediction............ 8 1.5 Some Fancier Ways One Might Approximate a Conditional Mean 9 1.5.1 (Non-)Linear Regression Methods (Least Squares Fitting) 9 1.5.2 Methods Based on Local Smoothing/Averaging...... 10 1.6 Complexity, Fit, and Choice of Tuning Parameters........ 11

2 Linear Methods (Ch 3 of HTF) 11 2.1 The Gram-Schmidt Process and the QR Decomposition..... 12 2.2 The Singular Value Decomposition of a Full Rank X....... 14 2.3 Ridge Regression and the Lasso and Some Generalizations Thereof 16 2.3.1 Ridge Regression....................... 16 2.3.2 The Lasso and Generalizations............... 17 2.4 Two Methods With Derived Input Variables............ 19 Course development supported by NSF grant DMS #0502347 EMSW21-RTG awarded to the Department of Statistics, Iowa State University.

3 Linear (and a Bit on Quadratic) Methods of ClassiÖcation (Ch

1 Introduction (Ch 1 and Ch 2 of HTF)

The course is (mostly) about "supervised" machine learning for statisticians. The fundamental issue here is prediction, usually with a fairly large number of predictors and a large number of cases upon which to build a predictor. For

X2 <p

an input vector (a vector of predictors) with jth coordinate Xj and

Y

some output value (usually univariate, and when itís not, weíll indicate so with some form of bold face) the object is to use N observed (X; Y ) pairs

(x 1 ; y 1 ) ; (x 2 ; y 2 ) ; : : : ; (xN ; yN )

called training data to create an e§ective prediction rule

Y^ b (X) = f (X)

"Supervised" learning means that the training data include values of the output variable. A primary di§erence between a "machine learning" point of view and that common in basic graduate statistics courses is an ambivalence toward making statements concerning parameters of any models used in the invention of pre- diction rules (including those that would describe the amount of variation in observables one can expect the model to generate). Standard statistics courses often conceive of those parameters as encoding scientiÖc knowledge about some underlying data-generating mechanism or real-world phenomenon. Machine learners donít seem to care much about these issues, but rather are concerned about "how good" a prediction rule is. An output variable might take values in < or in some Önite set G = f 1 ; 2 ; : : : ; Kg. In this latter case, it is often convenient to replace a G-valued output with K indicator variables Yj = I [Y ^ = j] ; j = 1; 2 ; : : : ; K

(of course) each taking real values. This replaces the original Y ^ with the vector output

Y =

B

B

B

Y 1

Y 2

YK

C

C

C

A

taking values in <K^.

1.1 Some Very Simple Probability Theory and Decision

Theory and Prediction Rules

For purposes of appealing to general theory that can suggest sensible forms for prediction rules, suppose that the random pair (X; Y ) has (joint) distribution P. (Until further notice all expectations refer to distributions and conditional distributions derived from P .) Suppose further that L (by; y)  0 is some loss function quantifying how unhappy I am with prediction yb when in fact Y = y. I might consider trying to choose the form of f to minimize

EL (f (X) ; Y )

This is (in theory) easily done, since

EL (f (X) ; Y ) = EE [L (f (X) ; Y ) jX]

and the minimization can be accomplished by minimizing the conditional mean for each possible value for X. That is, an optimal choice of prediction rule is deÖned by f (x) = arg min a

E [L (a; Y ) jX = x] (1)

In the simple case where L (y; yb ) = (yb y)^2 , the optimal prediction rule (1) is well known to be f (x) = E [Y jX = x] In a simple two-class classiÖcation context, where Y ^ takes values in G = f 1 ; 2 g, I might set up a decision problem with action space A = G and loss function

L (a; Y ) = I [a 6 = Y ] = I [a = 1] I [Y ^ = 2] + I [a = 2] I [Y ^ = 1]

An optimal decision rule corresponding to (1) is

a (x) =

1 if E [I [Y ^ = 1] jX = x]  : 5 2 if E [I [Y ^ = 1] jX = x] < : 5

Further, if I deÖne Y = I [Y ^ = 1] this is is

a (x) =

1 if E [Y jX = x]  : 5 2 if E [Y jX = x] < : 5

So in both the squared error loss context and in the 0 - 1 loss 2 -state classiÖ- cation context, (P ) optimal choice of predictor involves the conditional mean of an output variable (albeit the second is a 0 - 1 output variable). These strongly suggest the importance of Önding ways to approximate E[Y jX = x] in order to (either directly or indirectly) produce good prediction rules.

Letting

X

N p

B

B

B

x^01 x^02 .. . x^0 N

C

C

C

A

be a matrix with rows the input vectors for the N cases in the training data and

Y

N  1

B

B

B

y 1 y 2 .. . yN

C

C

C

A

the corresponding vector of output values in the training set, the usual Stat 511 material says that least squares Ötting of a linear form of conditional mean to the training data can be accomplished as

b (^) = (X^0 X)^1 X^0 Y

with corresponding predictor

Y^ b (X) = b^0 X

Regarding notation: As we must repeatedly refer to both the vector of inputs and the matrix of training values for the inputs, and considerable confusion is possible if we use the same bold face for both, I have decided to adopt the this dual notation of X for the Örst and X for the second. Since it is rare that one wants to refer to vector outputs, the notation Y will be mostly unambiguous as the (column) vector of output values in the training data.

1.3 The Curse of Dimensionality

Roughly speaking, itís clear that one wants to allow the most áexible kinds of prediction rules that a given training data set will adequately support Ötting. Naively, one might hope that with what seem like the "large" sample sizes in machine learning contexts, even if p is fairly large, highly áexible prediction rules (like k-nearest neighbor rules) might be practically useful (as points "Öll up" <p and allow one to Ögure out how Y behaves as a function of X, operating quite locally). But our intuition about how sparse data sets in <p^ actually must be is pretty weak and needs some education. There is the "curse of dimensionality" to be reckoned with. There are many ways of framing this inescapable sparsity. Some simple ones involve facts about uniform distributions on the unit ball in <p

fx 2 <pj kxk  1 g

and on a unit cube centered at the origin

[: 5 ; :5]p

For one thing, "most" of these distributions are very near the surface of the solids. The cube [r; :r]p^ capturing (for example) half the volume of the cube (half the probability mass of the distribution) has

r = :5 (:5)^1 =p

which converges to : 5 as p increases. Essentially the same story holds for the uniform distribution on the unit ball, except that the radius capturing half the probability mass has r = (:5)^1 =p

which converges to 1 as p increases. Points uniformly distributed in these solids are mostly near the surface or boundary of the spaces. Another interesting calculation concerns how large a sample must be in order for points generated from the uniform distribution on the ball or cube in an iid fashion to tend to "pile up" anywhere. Consider the problem of describing the distance from the origin to the closest of N iid points uniform in the unit ball. With R = the distance from the origin to a single random point

R has cdf

F (r) =

0 r < 0 rp^0  r  1 1 r > 1

So if R 1 ; R 2 ; : : : ; RN are iid with this distribution, M = min fR 1 ; R 2 ; : : : ; RN g has cdf

FM (m) =

0 m < 0 1 (1 mp)N^0  m  1 1 m > 1

This distribution has, for example, median

F M^1 (:5) = 1

 1 =N!^1 =p

For, say, p = 100 and N = 10^6 , the median of the distribution if M is : 87. In addition to these kinds of considerations of sparsity, there is the fact that the potential complexity of functions of p variables explodes exponentially in p.

1.4 Variance-Bias Considerations in Prediction

Just as in model parameter estimation, the "variance-bias trade-o§" notion is important in a prediction context. Here we consider a decomposition of what HTF in their Section 2.9 call the "test/generalization error" that can help us think about that trade-o§. In what follows, assume that (X 1 ; Y 1 ) ; (X 2 ; Y 2 ) ; : : : ; (XN ; YN ) are iid P and independent of (X; Y ) that is also P distributed. Write EN for expectation with respect to the joint distribution of the training data

  1. "spline functions." For example in p = 1 dimension with "knots" t 1 < t 2 <    < tM 2 , one might have

hm (x) = (x tm)+ for m = 1; 2 ; : : : ; M 2 hM 1 (x) = x and hM (x) = 1

Here predictions are piecewise linear in x. Products of such things with arguments coordinates of x 2 <p^ can be used for p > 1. Where knots are Öxed, Ötting is linear regression problem. If choosing knots is part of the Ötting process, this is a non-linear regression problem.

  1. "radial basis functions" (radially symmetric functions) like

exp

2 m

kx mk^2

for some parameters m and m. Where these are Öxed, Ötting is linear regression problem. If choosing the m and m part of the Ötting process, this is a non-linear regression problem.

1.5.2 Methods Based on Local Smoothing/Averaging

One might try choosing a function f (x) by balancing some measure of "Öt" against a penalty associated with how "wiggly/bizarre" the function is. For p = 1, it is possible to solve for  > 0 the optimization problem

f = arg min h with enough derivatives

X^ N

i=

(yi h (xi))^2 + 

Z

jh^00 (x)j 2 dx

and the optimizing function is a so-called "cubic smoothing spline." The integral above might be called J (h), and the larger is , the less wiggly is f. For p > 1 , one might try considering Ötting functions of the form

h (x) =

X^ p

j=

hj (xj )

using a penalty like



X^ p

j=

J (hj )

and hope to do something generalizing the p = 1 method. Similarly, one might consider a "projection pursuit regression" model that Öts

Y^ b (x) =

X^ M

m=

gm

mx

where the (^) m are unknown parameters and the real-valued functions of a sin- gle real variable gm are to be chosen as well (presumably using some penalty function idea and an iterative scheme that alternatively chooses (^) mís and gmís). Another possibility is the local use of weighted regression ideas. For some kernel function  (x 0 ; x), like for example,

 (x 0 ; x) =

exp

kx 0 xk^2

and some (usually fairly simple) function like

h (x) = 2 < or h (x) = 0 x

one might choose for each x 0

(x 0 ) = arg min

X^ N

i=

 (x 0 ; xi) (yi h (xi))^2

and then employ the prediction rule

Y^ b (x) = h (^) (x) (x)

(This produces smoothers like the loess smoother.)

1.6 Complexity, Fit, and Choice of Tuning Parameters

The methods presented at the end of Chapter 2 all have complexity parame- ters (the number of basis functions employed, the penalty weight, and the band width/neighborhood size parameter) that must be chosen by a user. If a choice of complexity parameter doesnít allow enough áexibility in the form of a pre- dictor, under-Öt occurs and there is large bias in prediction. On the other hand, if the choice allows too much áexibility, bias may be reduced, but the price paid is large variance and over-Öt. It is a theme that runs through this material that complexity must be chosen in a way that balances variance and bias for the particular combination of N and p and general circumstance one faces. SpeciÖcs of methods for doing this are presented later in the book.

2 Linear Methods (Ch 3 of HTF)

There is more to say about the development of a linear predictor

Y^ b (X) = 0 X

for an appropriate 2 <p^ than what is said in Stat 500 and Stat 511 (where least squares is used to Öt the linear form to all p input variables or to some subset of M of them). Some of that involves more linear algebra background than is assumed or used in Stat 511. We begin with some linear theory that

  1. Set the Örst column of Z to be

z 1 = x 1

  1. Having constructed Zl 1 = (z 1 ; z 2 ; : : : ; zl 1 ), let

zl = xl

X^ l^1

j=

xl; zj zj ; zj

zj

It is easy enough to see that zl; zj = 0 for all j < l (building up the orthogonality of z 1 ; z 2 ; : : : ; zl 1 by induction), since

zl; zj = xl; zj xl; zj

as at most one term of the sum in step 2. above is non-zero. Further, assume that C (Zl 1 ) = C (Xl 1 ). zl 2 C (Xl) and so C (Zl)  C (Xl). And since any element of C (Xl) can be written as a linear combination of an element of C (Xl 1 ) = C (Zl 1 ) and xl, we also have C (Xl)  C (Zl). Thus, as advertised, C (Zl) = C (Xl). Since the zj are perpendicular, for any N -vector w,

X^ l

j=

w; zj zj ; zj

zj

is the projection of w onto C (Zl) = C (Xl). (To see this, consider minimiza-

tion of the quantity

D

w

Pl j=1 cj^ zj^ ;^ w^ ^

Pl j=1 cj^ zj

E

= w

Pl j=1 cj^ zj

2 by

choice of the constants cj .) In particular, the sum on the right side of the equality in step 2. of the Gram-Schmidt process is the projection of xl onto C (Xl 1 ). And the projection of Y onto C (Xl) is

X^ l

j=

Y; zj zj ; zj

zj

This means that for a full p-variable regression,

Y; zp zp; zp

is the regression coe¢ cient for zp and (since only zp involves it) the last vari- able in X, xp. So, in constructing a vector of Ötted values, Ötted regression coe¢ cients in multiple regression can be interpreted as weights to be applied to that part of the input vector that remains after projecting onto the space spanned by all the others. The construction of the orthogonal variables zj can be represented in matrix form as X N p

= Z

N p

pp

where is upper triangular with

kj =^ the value in the^ kth row and^ jth column of^

=

zk; xj hzk; zki

DeÖning

D = diag

hz 1 ; z 1 i^1 =^2 ; : : : ; zp; zp

= diag (kz 1 k ; : : : ; kzpk)

and letting Q = ZD^1 and R = D

one may write X = QR (3)

that is the so-called QR decomposition of X. In (3), Q is N  p with

Q^0 Q = D^0 Z^0 ZD = D^0 diag

hz 1 ; z 1 i ; : : : ; zp; zp

D = I

That is, Q has for columns perpendicular unit vectors that form a basis for C (X). R is upper triangular and that says that only the Örst l of these unit vectors are needed to create xl. The decomposition is computationally useful in that (for qj the jth column of Q) the projection of Y onto C (X) is (since the qj comprise an orthonormal basis for C (X))

Y^ b =

X^ p

j=

Y; qj qj = QQ^0 Y (4)

and b OLS = R^1 Q^0 Y

(The fact that R is upper triangular implies that there are e¢ cient ways to compute its inverse.)

2.2 The Singular Value Decomposition of a Full Rank X

The matrix X has a so-called singular value decomposition as

X N p

= U

N p

D

pp

V 0

pp

where U has orthonormal columns spanning C (X), V has orthonormal columns spanning C (X^0 ) (the row space of X), and D = diag(d 1 ; d 2 ; : : : ; dp) for

d 1  d 2      dp > 0

The dj are the "singular values" of X.

is the sample covariance (and correlation) matrix for the p input variables X 1 ; X 2 ; : : : ; Xp.

2.3 Ridge Regression and the Lasso and Some General-

izations Thereof

An alternative to seeking to Önd a suitable level of complexity in a linear predic- tion rule through subset selection and least squares Ötting of a linear form to the selected variables, is to employ a shrinkage method based on a penalized ver- sion of least squares to choose a vector 2 <p^ to employ in a linear prediction rule. Here we consider several such methods. The implementation of these methods is not equivariant to the scaling used to express the input variables Xj. So that we can talk about properties of the methods that are associated with a well-deÖned scaling, we assume here that the output variable has been centered (i.e. that hY; 1 i = 0) and that the columns of X have been standardized (and if originally X had a constant column, it has been removed).

2.3.1 Ridge Regression

For a  > 0 the ridge regression coe¢ cient vector 2 <p^ is

b ridge  = arg min 2<p

X^ N

i=

@yi

X^ p

j=

j xij

A

2

  • 

X^ p

j=

2 j

Here  is a penalty/complexity parameter that controls how much b^

OLS is shrunken towards 0. The unconstrained minimization problem expressed in (6) has an equivalent constrained minimization description as

b ridge t = arg min with Pp j=1 2 j t

XN

i=

@yi

X^ p

j=

j xij

A

2 (7)

for an appropriate t > 0. (Corresponding to  used in (6), is t = b^

ridge 

2

used in (7). Conversely, corresponding to t used in (7), one may use a value of  in (6) producing the same error sum of squares.) The unconstrained form (6) calls upon one to minimize

(Y X )^0 (Y X ) +  0

and some vector calculus leads directly to

b ridge  = (X^0 X + I)^1 X^0 Y

So then, using the singular value decomposition of X,

Y^ b ridge = Xb^ ridge  = U DV 0

V DU 0 U DV 0 + I

V DU 0 Y

= U D

V 0

V DU 0 U DV 0 + I

V

DU 0 Y

= U D

D^2 + I

DU 0 Y

X^ p

j=

d^2 j d^2 j + 

Y; uj uj (8)

Comparing to (5) and recognizing that

d^2 j+ d^2 j+1 + 

d^2 j d^2 j + 

we see that the coe¢ cients of the orthonormal basis vectors uj employed to

get Yb

ridge are shrunken version of the coe¢ cients applied to get Yb

OLS : The most severe shrinking is enforced in the directions of the smallest principal components of X (the uj least important in making up low rank approximations to X). The function

df () = tr

X (X^0 X + I)

1 X^0

= tr

U D

D^2 + I

DU 0

= tr

X^ p

j=

d^2 j d^2 j + 

uj u^0 j

A

= tr

X^ p

j=

d^2 j d^2 j + 

u^0 j uj

A

X^ p

j=

d^2 j d^2 j + 

is called the e§ective degrees of freedom associated with the ridge regression. (Note that if  = 0 ridge regression is ordinary least squares and this is p, the usual degrees of freedom associated with projection onto C (X), i.e. trace of the projection matrix onto this column space. As ! 1, this goes to 0 .)

2.3.2 The Lasso and Generalizations

The "lasso" and the other relatives of ridge regression are the result of generaliz- ing the optimization criteria (6) and (7) by replacing

Pp j=

2 j with^

Pp j=1 j

q

between the ridge and lasso. For an 2 (0; 1) and some t > 0 , this is deÖned by

b elastic net t =^ arg min with Ppj=1( (^2) j +(1 )j (^) j j)t

XN

i=

@yi

X^ p

j=

j xij

A

2

The constraint is some kind of compromise between the ridge and lasso con- straints. The constraint regions have "corners" like the lasso regions but are more rounded than the lasso regions.

2.4 Two Methods With Derived Input Variables

Another possible approach to the problem of Önding an appropriate level of complexity in a Ötted linear prediction rule is to consider regression on some number M < p of predictors derived from the original inputs Xj. Two such methods discussed by HTF are the methods of Principal Components Regression and Partial Least Squares. Here we continue to assume that the columns of X have been standardized and Y has been centered.

2.4.1 Principal Components Regression

The idea here is to replace the p columns of predictors in X with the Örst few (M ) principal components of X (from the singular value decomposition of X)

zj = Xvj = dj uj

Correspondingly, the vector of Ötted predictions for the training data is

Y^ b PCR =

X^ M

j=

Y; zj zj ; zj

zj

X^ M

j=

Y; uj uj (12)

Comparing this to (5) and (8) we see that ridge regression shrinks the coe¢ cients of the principal components uj according to their importance in making up X, while principal components regression "zeros out" those least important in making up X.

Notice too, that Yb

PCR can be written in terms of the original inputs as

Y^ b PCR =

X^ M

j=

Y; uj

dj

Xvj

= X

X^ M

j=

Y; uj

dj

vj

A

= X

X^ M

j=

d^2 j

hY;Xvj i vj

A

so that

b PCR =

X^ M

j=

d^2 j

hY;Xvj i vj (13)

where (obviously) the sum above has only M terms. b^

OLS is the p = M version of (13). As the vj are orthonormal, it is therefore clear that

b PCR  b OLS

So principal components regression shrinks both Yb

PCR toward 0 in <N^ and b OLS toward 0 in <p.

2.4.2 Partial Least Squares Regression

The shrinking methods mentioned thus far have taken no account of Y in de- termining directions or amounts of shrinkage. Partial least squares speciÖcally employs Y. In what follows, we continue to suppose that the columns of X have been standardized and that Y has been centered. The logic of partial least squares is this. Suppose that

z 1 = Xw 1

is the linear combination of columns of X maximizing

jhY ; Xwij (14)

(which is essentially the sample covariance between the variables Y and X^0 w) subject to the constraint that kwk = 1. Then for j > 1 , let

zj = Xwj

be the linear combination of columns of X maximizing

jhY ; Xwij (15)