Docsity

Big Data Analysis - Linear Regression, Sbobinature di Database Distribuiti

Toggle sidebar
bg1
STATISTICAL LEARNING
The Advertising data set consists of the sales (output/dependent variable denoted with Y) of that
product in 200 diferent markets, along (insieme) with advertising budgets for the product in each of
those markets for three different media: TV, radio, and newspaper (input/indipendent variariables
denoted with X so X1, X2, X3). If we determine that there is an association between advertising and
sales, then we can instruct our client to adjust advertising budgets, thereby indirectly increasing
sales. In other words, our goal is to develop an accurate model that can be used to predict sales on
the basis of the three media budgets.
The plot displays sales, in thousands of units, as a function of TV, radio, and newspaper budgets, in
thousands of dollars, for 200 diferent markets. Each blue line represents a simple model that can be
used to predict sales using TV, radio, and newspaper, respectively.
We assume that there is some relationship between Y and X = (X1, X2,...,Xp), which can be written
in the very general form Y = f(X) + e. Here f is some fIxed but unknown function of X1,...,Xp, and e is
a random error term, which is independent of X and has mean zero. In this formulation, f represents
the systematic information that X provides about Y.
WHY ESTIMATE f?
• PREDICTION
In many situations, a set of inputs X are readily available, but the output Y cannot be easily obtained.
In this setting, since the error term averages to zero, we can predict Y using Yˆ = ˆf(X), where ˆf
represents our estimate for f, and Yˆ represents the resulting prediction for Y. In this setting, ˆf is
often treated as a black box, in the sense that one is not typically concerned with the exact form of
ˆf, provided that it yields (cede) accurate predictions for Y .
The accuracy of Yˆ as a prediction for Y depends on two quantities, which we will call the reducible
error and the irreducible error. In general, ˆf will not be a perfect estimate for f, and this inaccuracy
will introduce some error. This error is reducible because we can potentially improve the accuracy of
ˆf by using the most appropriate statistical learning technique to estimate f. However, even if it
were possible to form a perfect estimate for f, so that our estimated response took the form Yˆ =
f(X), our prediction would still have some error in it! This is because Y is also a function of e, which,
by definition, cannot be predicted using X. Therefore, variability associated with e also affects the
accuracy of our predictions. This is known as the irreducible error, because no matter how well we
estimate f, we cannot reduce the error introduced by e. Why is the irreducible error larger than
zero? The quantity e may contain unmeasured variables that are useful in predicting Y : since we
don’t measure them, f cannot use them for its prediction.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Anteprima parziale del testo

Scarica Big Data Analysis - Linear Regression e più Sbobinature in PDF di Database Distribuiti solo su Docsity!

STATISTICAL LEARNING

The Advertising data set consists of the sales (output/dependent variable denoted with Y) of that product in 200 diferent markets, along (insieme) with advertising budgets for the product in each of those markets for three different media: TV, radio, and newspaper (input/indipendent variariables denoted with X so X1, X2, X3). If we determine that there is an association between advertising and sales , then we can instruct our client to adjust advertising budgets, thereby indirectly increasing sales. In other words, our goal is to develop an accurate model that can be used to predict sales on the basis of the three media budgets. The plot displays sales, in thousands of units, as a function of TV, radio, and newspaper budgets, in thousands of dollars, for 200 diferent markets. Each blue line represents a simple model that can be used to predict sales using TV, radio, and newspaper, respectively. We assume that there is some relationship between Y and X = (X1, X2,...,Xp), which can be written in the very general form Y = f(X) + e. Here f is some fIxed but unknown function of X1,...,Xp, and e is a random error term, which is independent of X and has mean zero. In this formulation, f represents the systematic information that X provides about Y. WHY ESTIMATE f?

  • PREDICTION In many situations, a set of inputs X are readily available, but the output Y cannot be easily obtained. In this setting, since the error term averages to zero, we can predict Y using Yˆ = ˆf(X) , where ˆf represents our estimate for f, and Yˆ represents the resulting prediction for Y. In this setting, ˆf is often treated as a black box , in the sense that one is not typically concerned with the exact form of ˆf, provided that it yields (cede) accurate predictions for Y. The accuracy of Yˆ as a prediction for Y depends on two quantities, which we will call the reducible error and the irreducible error. In general, ˆf will not be a perfect estimate for f, and this inaccuracy will introduce some error. This error is reducible because we can potentially improve the accuracy of ˆf by using the most appropriate statistical learning technique to estimate f. However, even if it were possible to form a perfect estimate for f, so that our estimated response took the form Yˆ = f(X), our prediction would still have some error in it! This is because Y is also a function of e , which, by definition, cannot be predicted using X. Therefore, variability associated with e also affects the accuracy of our predictions. This is known as the irreducible error, because no matter how well we estimate f, we cannot reduce the error introduced by e. Why is the irreducible error larger than zero? The quantity e may contain unmeasured variables that are useful in predicting Y : since we don’t measure them, f cannot use them for its prediction.

Consider a given estimate ˆf and a set of predictors X, which yields the prediction Yˆ = ˆf(X). Assume for a moment that both ˆf and X are fxed, so that the only variability comes from e. where E(Y − Yˆ )2 represents the average, or expected value, of the squared difference between the predicted and actual value of Y , and Var(e) represents the variance associated with the error term e. Our aim is to estimate f minimizing the reducible error. Irreducible error provide an upper bond on the accuracy of our prediction for Y and this bound is always unknown in practice. HOW DO WE ESTIMATE f? PARAMETRIC METHODS The linear model is an important example of a parametric model: fL(X) = β0 + β1X1 + β2X2 +... βpXp Once we have assumed that f is linear, the problem of estimating f is greatly simplifed. Instead of having to estimate an entirely arbitrary p-dimensional function f(X), one only needs to estimate the p + 1 coefficients β0, β1,..., βp. After we select a model we need a procedure that uses the training data to fit the model, in the case of linear model we have to estimate all the parameters β0, β1,..., βp, one of the approach is least squares This method reduces the problem of estimating f down to one of estimating a set of parameters. Assuming a parametric form for f simplifes the problem of estimating f because it is generally much easier to estimate a set of parameters, such as β0, β1,..., βp in the linear model, than it is to fit an entirely arbitrary function f. The potential disadvantage of a parametric approach is that the model we choose will usually not match the true unknown form of f. If the chosen model is too far from the true f, then our estimate will be poor. We can try to address this problem by choosing flexible models that can fit many different possible functional forms for f. But in general, fitting a more flexible model requires estimating a greater number of parameters. These more complex models can lead to a phenomenon known as overfitting the data, which essentially means they follow the errors, or noise, too closely.

  • Generalized additive models (GAMs) are more fexible than linear regression. They are also somewhat less interpretable than linear regression, because the relationship between each predictor and the response is now modeled using a curve
  • Fully non-linear methods such as bagging ASSESTING MODEL ACCURACY In order to evaluate the performance of a statistical learning method on a given data set, we need some way to measure how well its predictions actually match the observed data quantifying how the predicted response is close to the true response. In the regression setting, the most commonly-used measure is the mean squared error (MSE) where ˆf(xi) is the prediction that ˆf gives for the ith observation. The MSE will be small if the predicted responses are very close to the true responses, and will be large if for some of the observations, the predicted and true responses differ substantially. LINEAR REGRESSION Linear regression is a useful tool for predicting a quantitative response. It is a very straightforward approach for predicting a quantitative response Y on the basis of a single predictor variable X. It assumes that there is approximately a linear relationship between X and Y. Mathematically, we can write this linear relationship as Y ≈ β0 + β1X ( read “≈” as “is approximately modeled as”). β0 + β1 unknown costants that represent the intercept and the slope terms in the linear model, are known as the model coefficients or parameters. yˆ = βˆ0 + βˆ1x that represent a prediction of Y using our training data to produce estimates β0 + β to predict our future sale (in this case).

This defines the least squares coeffcient estimates for simple linear regression. We assume that the true relationship between X and Y takes the form Y = f(X) + " for some unknown function f, where " is a mean-zero random error term. If f is to be approximated by a linear function, then we can write this relationship as Y = β0 + β1X + e. The error term is a catch-all for what we miss with this simple model: the true relationship is probably not linear, there may be other variables that cause variation in Y , and there may be measurement error. We typically assume that the error term is independent of X. The concept of these two lines is a natural extension of the standard statistical approach of using information from a sample to estimate characteristics of a large population. For example, suppose that we are interested in knowing the population mean μ of some random variable Y. Unfortunately, μ is unknown, but we do have access to n observations from Y , y1,...,yn, which we can use to estimate μ. A reasonable estimate is μˆ = ¯y, where y¯ = 1 n )n i=1 yi is the sample mean. The sample mean and the population mean are different, but in general the sample mean will provide a good estimate of the population mean. In the same way, the unknown coefcients β0 and β1 in linear regression define the population regression line. We seek to estimate these unknown coefcients using βˆ0 and βˆ1 given in. These coeffcient estimates define the least squares line. We can wonder how close βˆ0 and βˆ1 are to the true values β0 and β1. To compute the standard errors associated with βˆ0 and βˆ1, we use the following formulas: where σ2 = Var(e) This estimate of σ is known as the residual standard error, and is given by the formula residual standard error RSE = radquadratadiRSS/(n − 2). Standard errors can be used to compute confidence intervals, if we take repeated samples and construct the confidence interval for each sample, 95% of the intervals will contain the true unknown value of the parameter. There is approximately a 95% chance that the interval will contain the true value of β1 (under a scenario where we got repeated samples like the present sample) For the advertising data, the 95% confidence interval for β1 is [0.042, 0.053]

The RSE is considered a measure of the lack of ft of the model to the data. If the predictions obtained using the model are very close to the true outcome values will be small , and we can conclude that the model fits the data very well. On the other hand, if yˆi is very far from yi for one or more observations, then the RSE may be quite large , indicating that the model doesn’t fit the data well. The R2 statistic provides an alternative measure of ft. It takes the form of a proportion—the proportion of variance explained—and so it always takes on a value between 0 and 1, and is independent of the scale of Y. We use the formula where TSS = )(yi − y¯)2 is the total sum of squares and measures the total variance in the response Y and can be thought of as the amount of variability inherent in the response before the regression is performed. In contrast, RSS measures the amount of variability that is left unexplained after performing the regression. Hence, TSS − RSS measures the amount of variability in the response that is explained (or removed) by performing the regression, and R2 measures the proportion of variability in Y that can be explained using X. An R2 statistic that is close to 1 indicates that a large proportion of the variability in the response is explained by the regression. A number near 0 indicates that the regression does not explain much of the variability in the response; this might occur (verificarsi) because the linear model is wrong, or the error variance σ2 is high, or both. MULTIPLE LINEAR REGRESSION Instead of fitting a separate simple linear regression model for each predictor, a better approach is to extend the simple linear regression model so that it can directly accommodate multiple predictors. We can do this by giving each predictor a separate slope coefficient in a single model. In general, suppose that we have p distinct predictors. Then the multiple linear regression model takes the form where Xj represents the jth predictor and βj quantifes the association between that variable and the response. We interpret βj as the average effect on Y of a one unit increase in Xj , holding all other predictors fixed. In the advertising example, becomes sales = β0 + β1 × TV + β2 × radio + β3 × newspaper + e. As was the case in the simple linear regression setting, the regression coeffcients β0, β1,..., βp in (3.19) are unknown, and must be estimated. Given estimates βˆ0, βˆ1,..., βˆp, we can make predictions using the formula

The parameters are estimated using the same least squares approach that we saw in the context of simple linear regression. We choose β0, β1,..., βp to minimize the sum of squared residuals The approach of using an F-statistic to test for any association between the predictors and the response works when p is relatively small , and certainly small compared to n. However, sometimes we have a very large number of variables. If p>n then there are more coefficients βj to estimate than observations from which to estimate them. In this case we cannot even fit the multiple linear regression model using least squares, so the F-statistic cannot be used. When p is large , some of the approaches discussed in the next section, such as forward selection , can be used. Even for moderate p, trying out every possible subset of the predictors is infeasible. For instance, we saw that if p = 2, then there are 22 = 4 models to consider. But if p = 30, then we must consider 230 = 1,073,741,824 models! This is not practical. Therefore, unless p is very small, we cannot consider all 2p models, and instead we need an automated and efficient approach to choose a smaller set of models to consider. There are three classical approaches for this task:

  • Forward selection We begin with the null model—a model that contains intercept but no predictors. We then ft p simple linear regressions and add to the null model the variable that results in the lowest RSS. We then add to that model the variable that results in the lowest RSS for the new two-variable model. This approach is continued until some stopping rule is satisfed.
  • Backward selection We start with all variables in the model, and backward selection remove the variable with the largest p-value—that is, the variable that is the least statistically signifcant. The new (p − 1)-variable model is ft, and the variable with the largest p-value is removed. This procedure continues until a stopping rule is reached. For instance, we may stop when all remaining variables have a p-value below some threshold
  • Mixed selection This is a combination of forward and backward selection. We start with no variables in the model, and as with forward selection, we add the variable that provides the best fit. We continue to add variables one-by-one. Of course, as we noted with the Advertising example, the p-values for variables can become larger as new predictors are added to the model. Hence, if at any point the p-value for one of the variables in the model rises above a certain threshold, then we remove that variable from the model. We continue to perform these forward and backward steps until all variables in the model have a sufficiently low p-value, and all variables outside the model would have a large p-value if added to the model. Backward selection cannot be used if p>n, while forward selection can always be used. Forward selection is a greedy approach, and might include variables early that later become redundant. Mixed selection can remedy this. LINEAR MODEL SELECTION AND REGULARIZATION Alternative fitting procedures can yield better prediction accuracy and model interpretability.

set of models with diferent numbers of variables. However, a number of techniques for adjusting the training error for the model size are available. These approaches can be used to select among a set of models with diferent numbers of variables. We now consider four such approaches: Cp, Akaike information criterion (AIC), Bayesian information criterion (BIC), and adjusted R2. For a fitted least squares model containing d predictors, the Cp estimate of test MSE is computed using the equation: e σˆ2 is an estimate of the variance of the error e associated with each response measurement, Cp statistic adds a penalty of 2dσˆ2 to the training RSS in order to adjust for the fact that the training error tends to underestimate the test error. Clearly, the penalty increases as the number of predictors in the model increases. Cp is an unbiased estimate of test MSE. As a consequence, the Cp statistic tends to take on a small value for models with a low test error, so when determining which of a set of models is best, we choose the model with the lowest Cp value. The AIC criterion is defined for a large class of models fit by maximum likelihood. BIC is derived from a Bayesian point of view, but ends up looking similar to Cp (and AIC) as well. For the least squares model with d predictors, the BIC is, up to irrelevant constants, given by Like Cp, the BIC will tend to take on a small value for a model tenderà ad assumere un valore più piccolo per un modello con un test error basso) with a low test error, and so generally we select the model that has the lowest BIC value. Notice that BIC replaces the 2dσˆ2 used by Cp with a log(n)dσˆ2 term, where n is the number of observations. Since log n > 2 for any n > 7, the BIC statistic generally places a heavier penalty on models with many variables, and hence results in the selection of smaller models than Cp. The adjusted R2 statistic is another popular approach for selecting among a set of models that contain diferent numbers of variables. the usual R2 is defined as 1 − RSS/TSS, where TSS = (yi − y)2 is the total sum of squares for the response. Since RSS always decreases as more variables are added to the model, the R2 always increases as more variables are added.

Unlike Cp, AIC, and BIC, for which a small value indicates a model with a low test error, a large value of adjusted R2 indicates a model with a small test error. The intuition behind the adjusted R2 is that once all of the correct variables have been included in the model, adding additional noise variables will lead to only a very small decrease in RSS. Since adding noise variables leads to an increase in d, such variables will lead to an increase in RSS/ n−d−1 , and consequently a decrease in the adjusted R2. The model with the largest adjusted R2 will have only correct variables and no noise variables. Unlike the R2 statistic, the adjusted R2 statistic pays a price for the inclusion of unnecessary variables in the model. VALIDATION AND CROSS-VALIDATION As an alternative to the approaches just discussed, we can directly estimate the test error using the validation set and cross-validation. We can compute (calcolare) the validation set error or the cross- validation error for each model under consideration, and then select the model for which the resulting estimated test error is smallest. This procedure has an advantage relative to AIC, BIC, Cp, and adjusted R2, in that it provides a direct estimate of the test error. It is in fact a statistical technique that allows the data to be used alternately for both the train and the test. I divide the initial dataset into a series of equal portions of data (k-fields) and iteratively use a certain number for the train and a certain number for the test. (Immaginiamo di avere 100 mail nel nostro dataset. Al posto di usarne 75 per addestrare il modello e 25 per testarlo (o valutarlo), divideremo i dati in 5 segmenti da 20 osservazioni. Ne useremo ogni volta 4 per addestrarlo e la restante parte per valutarlo. E questo lo farò finché non avrò usato ogni parte di dati per addestrare e per valutare il modello e i suoi risultati.) I can thus select the partial tree with the highest predictive value and use it as a model. The selected tree is the one that is least affected by the noise caused by the irrelevant attributes present in the dataset (overfitting).

In the left-hand panel, each curve corresponds to the ridge regression coefcient estimate for one of the ten variables, plotted as a function of λ. For example, the black solid line represents the ridge regression estimate for the income coefcient, as λ is varied. At the extreme left-hand side of the plot, λ is essentially zero, and so the corresponding ridge coefcient estimates are the same as the usual least squares estimates. But as λ increases, the ridge coefcient estimates shrink towards zero. When λ is extremely large, then all of the ridge coefcient estimates are basically zero. x-axis in the right-hand panel of Figure 6.4 as the amount that the ridge regression coefficient estimates have been shrunken towards zero; a small value indicates that they have been shrunken very close to zero. The ridge regression minimizes the sum of square residuals + l x the slope2. The slope2 adds a penalty to the traditional Least Square method and l determines how severe this penalty is. When l=0 then the Ridge Regression is also 0, so the line will only minimize the sum of square residuals so it will be the same as Least Square Line because they are both minimizing the exact same thing. The larger we make l the sloper gets asymptotically close to 0. Soo the larger l gets, our predictions for one parameter become less and less sensitive to the other parameter. THE LASSO Ridge regression does have one obvious disadvantage. Unlike best subset, forward stepwise, and backward stepwise selection, which will generally select models that involve just a subset of the variables, ridge regression will include all p predictors in the final model. The penalty will shrink all of the coefficienfs towards zero, but it will not set any of them exactly to 0 (unless l = infinito). This may not be a problem for prediction accuracy, but it can create a challenge in model interpretation in

settings in which the number of variables p is quite large. Increasing the value of λ will tend to reduce the magnitudes of the coefcients, but will not result in exclusion of any of the variables The lasso is a relatively recent alternative to ridge regression that over- comes this disadvantage. The lasso coefcients, βˆL λ , minimize the quantity As with ridge regression, the lasso shrinks the coefficient estimates towards zero. However, in the case of the lasso, the %1 penalty has the efect of forcing some of the coefcient estimates to be exactly equal to zero when the tuning parameter λ is sufciently large. Hence, much like best subset selection, the lasso performs variable selection. A s a result, models generated from the lasso are generally much easier to interpret than those produced by ridge regression. We say that the lasso yields sparse models—that is, sparse models that involve only a subset of the variables. As in ridge regression, selecting a good value of λ for the lasso is critical; Hence, depending on the value of λ, the lasso can produce a model involving any number of variables. In contrast, ridge regression will always include all of the variables in the model, although the magnitude of the coefcient estimates will depend on λ

Suppose that we would like to estimate the test error associated with ftting a particular statistical learning method on a set of observations. The validation set approach is a very simple strategy that consists into dividing the available set of observation into 2 parts: training set and validation set. The model is fit on the training set, and t he fitted model is used to predict the responses for the observations in the validation set. The resulting validation set error rate—typically assessed using MSE in the case of a quantitative response—provides an estimate of the test error rate. A schematic display of the validation set approach. A set of n observations are randomly split into a training set (shown in blue, containing observations 7, 22, and 13, among others) and a validation set (shown in beige, and containing observation 91, among others). The statistical learning method is ft on the training set, and its performance is evaluated on the validation set.