Least Squares Regression Outline 1 Regression and Conditional Expectation

Least Squares Regression Outline 1 Regression and Conditional Expectation

CIS 520: Machine Learning Spring 2018: Lecture 4 Least Squares Regression Lecturer: Shivani Agarwal Disclaimer: These notes are designed to be a supplement to the lecture. They may or may not cover all the material discussed in the lecture (and vice versa). Outline • Regression and conditional expectation • Linear least squares regression • Ridge regression and Lasso • Probabilistic view 1 Regression and Conditional Expectation In this lecture we consider regression problems, where there is an instance space X as before, but labels and predictions are real-valued: Y = Yb = R (such as in a weather forecasting problem, where instances might be satellite images showing water vapor in some region and labels/predictions might be the amount of rainfall in the coming week, or in a stock price prediction problem, where instances might be feature vectors describing properties of stocks and labels/predictions might be the stock price after some time period). Here m one is given a training sample S = ((x1; y1);:::; (xm; ym)) 2 (X × R) , and the goal is to learn from S a regression model fS : X!R that predicts accurately labels of new instances in X . What should count as a good regression model? In other words, how should we measure the performance of a regression model? A widely used performance measure involves the squared loss function, `sq : R×R!R+, defined as 2 `sq(y; yb) = (yb − y) : 2 The loss of a model f : X!R on an example (x; y) is measured by `sq(y; f(x)) = (f(x) − y) . Assuming examples are drawn from some joint probability distribution D on X ×R, the squared-loss generalization error of f : X!R w.r.t. D is then given by sq 2 erD [f] = E(X;Y )∼D (f(X) − Y ) : What would be the optimal regression model for D under the above loss? We have, sq 2 erD [f] = EX EY jX (f(X) − Y ) : 2 Now, for each x, we know (and it is easy to see) that the value c minimizing EY jX=x[(c − Y ) ] is given by c∗ = E[Y jX = x]. Therefore the optimal regression model is simply the conditional expectation function, also called the regression function of Y on x: f ∗(x) = E[Y jX = x] : 1 2 Least Squares Regression The conditional expectation function plays the same role for regression w.r.t. squared loss as does a Bayes optimal classifier for binary classification w.r.t. 0-1 loss. The minimum achievable squared error w.r.t. D is simply sq;∗ sq sq ∗ 2 erD = inf erD [f] = erD [f ] = EX EY jX (Y − E[Y jX]) = EX Var[Y jX] ; f:X!R which is simply the expectation over X of the conditional variance of Y given X; this plays the same role as the Bayes error for 0-1 binary classification. 2 Linear Least Squares Regression d m For the remainder of the lecture, let X = R , and let S = ((x1; y1);:::; (xm; ym)) 2 (X × R) . We start with a simple approach which does not make any assumptions about the underlying probability distribution, > but simply fits a linear regression model of the form fw(x) = w x to the data by minimizing the empirical sq 1 Pm 2 squared error on S, erb S [fw] = m i=1(fw(xi) − yi) : m 1 X > 2 min w xi − yi : (1) w2 d m R i=1 Setting the gradient of the above objective to zero yields m 2 X w>x − y x = 0 : m i i i i=1 We can rewrite this using matrix notation as follows: let 2 > 3 0 1 − x1 − y1 > 6 − x2 − 7 B y2 C X = 6 7 2 m×d and y = B C 2 m ; 6 . 7 R B . C R 4 . 5 @ . A > − xm − ym then we have X>Xw − X>y = 0 : These are known as the normal equations for least squares regression and yield the following solution for w (assuming X>X is non-singular): > −1 > wb = (X X) X y : The linear least squares regression model is then given by > fS(x) = wb x : m The solution wb can be viewed as performing an orthogonal projection of the label vector y in R onto the > m d-dimensional subspace (assuming m > d) spanned by the d vectors x~k = (x1k; : : : ; xmk) 2 R , k = 1; : : : ; d (in particular, the vector yb = Xwb constitutes the projection of y onto this subspace). We will see below that the same regression model also arises as a maximum likelihood solution under suitable probabilistic assumptions. Before doing so, we discuss two variants of the above model that are widely used in practice. 3 Ridge Regression and Lasso We saw above that the simple least squares regression model requires X>X to be non-singular; indeed, when X>X is close to being singular (which is the case if two or more columns of X are nearly co-linear), then Least Squares Regression 3 wb can contain large values that lead to over-fitting the training data. To prevent this, one often adds a penalty term or a regularizer to the objective in Eq. (1) that penalizes large values in w (such methods are also referred to as parameter shrinkage methods in statistics). 2 Pd 2 A widely used regularizer is the L2 regularizer kwk2 = j=1 wj , leading to the following: m 1 X > 2 2 min w xi − yi + λkwk2 ; (2) w2 d m R i=1 where λ > 0 is a suitable regularization parameter that determines the trade-off between the two terms. Setting the gradient of the above objective to zero again yields a closed-form solution for w: > −1 > wb = X X + λmId X y ; > where Id denotes the d × d identity matrix; note that the matrix X X + λmId is non-singular. The resulting regression model, > fS(x) = wb x ; is known as ridge regression and is widely used in practice.1 Pd Another regularizer that is frequently used is the L1 regularizer kwk1 = j=1 jwjj, which leads to m 1 X > 2 min w xi − yi + λkwk1 ; (3) w2 d m R i=1 where λ > 0 is again a suitable regularization parameter. This can be formulated as a quadratic programming problem which can be solved using numerical optimization methods. For large enough λ, the solution wb turns out to be sparse, in the sense that many of the parameter values in wb are equal to zero, so that the resulting regression model depends on only a small number of features. The L1-regularized least squares regression model is known as lasso and is also widely used, especially in high-dimensional problems where d is large and dependence on a small number of features is desirable. For both L1 and L2 regularizers, the regularization parameter λ determines the extent of the penalty for large values in the parameter vector w. In practice, one generally selects λ heuristically from some finite range using a validation set (which involves holding out part of the training data for validation, training on the remaining data with different values of λ, and selecting the one that gives highest performance on the validation data) or cross-validation (which involves dividing the training sample into some k sub- samples/folds, holding out one of these folds at a time and training on the remaining k − 1 folds with different values of λ, testing performance on the held-out fold, and repeating this procedure for all k folds; the value of λ that gives the highest average performance over the k folds is then selected2). In recent years, algorithms for certain models (including lasso) have been developed that can efficiently compute the entire path of solutions for all values of λ. Below we will also see a Bayesian interpretation of these regularizers; this gives another approach to selecting λ. 4 Probabilistic View We will now make a specific assumption on the conditional distribution of Y given x, and will see that estimating the parameters of that distribution from the training sample using maximum likelihood estimation and using the conditional expectation associated with the estimated distribution as our regression model 1 The same regularizer is also widely used in logistic regression, leading to L2-regularized logistic regression. 2An extreme case of cross-validation with k = m leads to what is called leave-one-out validation. 4 Least Squares Regression will recover the linear least squares regression model described above. We will also see that under the same probabilistic assumption, maximum a posteriori (MAP) estimation of the parameters under suitable priors will yield ridge regression and lasso. Specifically, assume that given x 2 X , a label Y is generated randomly as follows: Y = w>x + ; where w 2 Rd and ∼ N (0; σ2) is some normally distributed noise with variance σ2 > 0. In other words, we have Y jX = x ∼ N (w>x; σ2) ; so that the conditional density of Y given x can be written as 1 (y − w>x)2 p(y j x; w; σ) = p exp − : 2πσ 2σ2 Clearly, in this case, the optimal regression model (under squared error) is given by f ∗(x) = E[Y jX = x] = w>x : In practice, the parameters w; σ are unknown and must be estimated from the training sample S = ((x1; y1);:::; (xm; ym)), which is assumed to contain examples drawn i.i.d. from the same distribution. Let us first proceed with maximum likelihood estimation. Maximum likelihood estimation. We can write the conditional likelihood of w; σ as m m > 2 Y Y 1 (yi − w xi) L(w; σ) = py ; : : : ; y j x ;:::; x ; w; σ = p(y j x ; w; σ) = p exp − : 1 m 1 m i i 2σ2 i=1 i=1 2πσ The log-likelihood becomes m > 2 m X (yi − w xi) ln L(w; σ) = − ln(2π) − m ln σ − : 2 2σ2 i=1 Clearly, maximizing the above log-likelihood w.r.t.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    5 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us