Docsity

Dispensa di Statistical Learning, Dispense di Statistica

Toggle sidebar
bg1
STATISTICAL LEARNING
COURSE INTRODUCTION
Statistical learning: a wide set of tools for understanding data. These tools can be
classified as supervised or unsupervised.
Data Science it was a synonymous of statistics. But then, some years later, they
started to talk about a new discipline, is no longer just statistic, but it is different.
Currently is no consensus on the definition of data science. In data science
teamwork is very important. Data is used to help with marketing decision. Data
Science is a discipline aimed at extracting knowledge from data in various forms
it is applicable to a wide range of fields.
Different level of human input in the descriptive (What happened?), diagnostic
(Why did it happen?), predictive (What will happen?), and prescriptive statistics
(What should I do?).
Import  tidy data. Then an exploration part we consider as a loop. And then the
communication.
Data are used to help make decisions.
In general, a data-informed approach is the strategic option for more complex
decisions It is important to have quality and complete data.
We must have in mind the cycle of the data.
Statistical learning:
1) supervised SL (quello che studiamo durante il corso)  we have an output that
we want to predict or study based on one or more inputs
2) unsupervised SL (statistics for machine learning course, second year) we
have not the output but we want to study the structures and relationship
Aim: investigate factors that relate to wages for a group of US males. We wish
to understand the association between an employee’s age and education, as
well ad the calendar year, on his wage.
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

Anteprima parziale del testo

Scarica Dispensa di Statistical Learning e più Dispense in PDF di Statistica solo su Docsity!

STATISTICAL LEARNING

COURSE INTRODUCTION

Statistical learning: a wide set of tools for understanding data. These tools can be classified as supervised or unsupervised. Data Science it was a synonymous of statistics. But then, some years later, they started to talk about a new discipline, is no longer just statistic, but it is different. Currently is no consensus on the definition of data science. In data science teamwork is very important. Data is used to help with marketing decision. Data Science is a discipline aimed at extracting knowledge from data in various forms it is applicable to a wide range of fields. Different level of human input in the descriptive (What happened?), diagnostic (Why did it happen?), predictive (What will happen?), and prescriptive statistics (What should I do?). Import  tidy data. Then an exploration part we consider as a loop. And then the communication. Data are used to help make decisions. In general, a data-informed approach is the strategic option for more complex decisions It is important to have quality and complete data. We must have in mind the cycle of the data. Statistical learning:

  1. supervised SL (quello che studiamo durante il corso)  we have an output that we want to predict or study based on one or more inputs
  2. unsupervised SL (statistics for machine learning course, second year)  we have not the output but we want to study the structures and relationship Aim: investigate factors that relate to wages for a group of US males. We wish to understand the association between an employee’s age and education, as well ad the calendar year, on his wage.
  1. Wage increases with Age but decreases after age approx. 60.
  2. Wage as function of Year.
  3. Wage as a function of Education Level. Educational level is qualitative variable, are categories. So, we have a box plot. We cannot consider it like a quantitative variable. (educational level are not number) Combining all the three factors allows us to better understand the phenomenon and get more accurate predictions of a given man’s wage. Wage is a continuous quantitative output variable Predicting wage is a regression problem. There are also classification problems like Stock Market Data (Slide 38). There are statistical learning methods that allow us to identify some weak trends in the data and correctly predict the market movements most of the times (at least for this 5-year period). Today’s direction is a binary output variable. Predicting today’s direction is a classification problem. Nowadays, the field of SL is flourishing:
  • New and improved approaches aimed at answering new research questions in several different application fields.
  • New and improved software packages have eased the implementation of many SL methods. Notation and simple matrix algebra (Slide 45-49). Input  nature  output  we can think of nature as a very general Data Generator Process (DGP) and SL aims at approximating nature by means of models in the best possible way. Models are representation of reality. Data2 are more affective of random noise, the first one (data1) represent better the function of DGP.

STATISTICAL LEARNING

Advertising data  Aim: to give advice to a company on how to improve sales, by adjusting advertising budgets (advertising budgets: TV, Radio, Newspaper). In SL: to investigate the relationship between sales and the three advertising budgets and develop a model to predict sales on basis of the three advertising budgets.

How estimate f?  there is different approach to estimate f  training data (a set of n data points used to train our method for estimating f): Our aim is to apply a SL method to the training data to estimate the unknown

function f, i.e. to find a function f^ such that Y ≈ f^ (X) for any observation (X,Y).

We distinguish parametric and non-parametric SL methods.  PARAMETRIC SL METHODS Parametric methods simplify the problem of estimating f to one of estimating set of parameters.  NON-PARAMETRIC SL METHODS Non-parametric methods do not make explicit assumptions about the functional form of f: they look for an estimate of f that is as close as possible to the data points, without being too rough or too wiggly.

Nonparametric SL are sometimes a lot complicated, we need a lot of data There exist a trade-off between flexibility (and prediction accuracy) and model interpretability. When we are only interested in inference, simple and relatively inflexible SL methods are preferable. When we are only interested in prediction, the most flexible SL methods are sometimes preferable (they can suffer from overfitting).

  • Supervised SL problems:  Regression problems: the response is a quantitative variable  Classification problems: the response is a quantitative or categorical variable
  • Unsupervised SL problems We study several SL methods because a single best method does not exist for all possible data sets. It is important to be able to assess model accuracy, in order to decide, for any given data set, which method produces the best results. First, we refer to the regression setting. QUALITY OF FIT To evaluate the performance of a SL method we need to measure the extent to

which, for a given observation i, the predicted response value f^ (xi) is close to

the true response value yi. Data with three different model, we are increasing the level of flexibility of the model moving from orange to blue to green. The best model that fit the

Variance of f^ (x 0 ) refers to the amount by which f^ would change if we

estimated it using a different training set. In general, more flexible SL methods have higher variance.

Bias of f^ (x 0 ) refers to the difference between the true f and the estimated f^

and measures the error introduced by approximating a real phenomenon by a model. In general, more flexible SL methods have lower bias. General rule: as flexibility increases, variance will increase and bias will decrease; the test MSE will increase or decrease, depending on the relative change of variance and bias. The aim is to find a SL method with low variance and low squared bias. THE BAYES CLASSIFIER The test error rate is minimized, on average, by the Bayes classifier. It is a very simply method that assigns each observation to the most likely class, given its predictor values. Given a test observation with predictor x 0 , we assign it to the class j for which the conditional probability is largest. If I have a new observation that has a predicted values x1 and x2, I will classified the customer in the blue category. We have an area where the probability to be orange is

under 50%. (Nell’angolo in basso a destra la probabilità che sia arancione è zero  la probabilità che sia blu quindi è del 100%.) In the example (simulated data): Bayes error rate = 0. The Bayes error rate is analogous to the irreducible error. For real data, the Bayes classifier cannot be computed, because the conditional distribution of Y given X is unknown. In practice, SL classification methods estimate the conditional distribution of Y given X and classify a given observation to the class with the highest estimated probability. Examples:

  • K-Nearest Neighbors (KNN) classifier
  • Logistic regression model We are interesting in predicting the class of orange and blue. Of X we know the value of income and age. We don’t know the class of orange or blue. We start with KNN algorithm. The circle is because we just choose three neighbourhood. Step 2, we must compute the fraction of orange and blue in the circle. Orange 1/3 and blue 2/3. I assign the point to the blue class. We repeat this for all points in the space. C’è più probabilità che i punti all’interno del cerchio siano blu piuttosto che arancioni. KNN decision boundary is when we have probability same, equal to 0,5.

About the Multiple LRM we must made some classical assumption: With p = 2 the LS regression line becomes a plane, that minimize the sum of the squared vertical distances between each observation and the plane. The OLS estimates of the parameters minimize the objective function (Residual Sum of Squares-RSS), each estimate Betaj is a linear transformation of y like y^. Under the classical assumptions, the OLS estimators:  are BLUE: best (most efficient) linear unbiased estimators in the class of linear and unbiased estimators (Gauss Markov theorem).  under general conditions, they have optimal asymptotic properties (consistency, asymptotic Normality -if errors are independent- and efficiency in the class of unbiased estimators for Beta). The Residual Standard Error RSE and the variance-covariance matrix of the OLS estimators: In order to apply the ML estimation method, we add a new error to the classical assumptions. The ML estimators for Beta do coincide with the OLS estimators, they have the same properties 

The estimate of 𝛽𝑗 can be interpreted as the average effect on 𝑌 of a one-unit increase in 𝑋𝑗 , holding all other predictors fixed, In order to compare the effects 𝛽𝑗 of several predictors we compute the so-called Beta coefficients  where s is the estimate of the standard deviation. Beta coefficients do coincide with the parameter estimates of the model where all variables (both response and predictors) are previously standardized. Confidence interval and tests for beta  The confidence interval provides a set of plausible values for 𝜗 that includes 𝜗 with a high level of confidence. We can just invoke the long run relative frequency interpretation of probability and say that we are highly confident that it includes 𝜗. Hypothesis tests for parameters: Standard errors are also used to perform hypothesis tests on the parameters; there are two possible tests: T = ß-b over SE and T = ß over SE.

When 𝑝 is very large with 𝑝 > 𝑛, the 𝐹-statistic cannot be used (we cannot even fit the multiple LRM). There exist another F-statistic useful to test that a particular subset of 𝑞 of the parameters are zero. F-statistic for a subset of q predictors:  Do all the predictors help to explain 𝑌, or is only a subset of the predictors useful? Identifying which predictors are associated with 𝑌 in order to fit a model involving only those predictors is referred to as variable selection. Classical approaches for variable selection are the stepwise procedures (which must be performed within the theoretical framework of the application field). The stepwise procedure compares several different models, each containing a different subset of the predictors, and selects the best model according to a measure of model quality To judge the quality of a model, we can use several indices. The most common are in the class of the Information Criteria, like AIC and BIC. Where L is the max value of the likelihood function and k the n of model parameters, the model with lowest AIC or BIC is selected as the best model. In general, the indices of model quality are defined as a function of the number of parameters in order to take account of the trade-off between:  the improvement of the goodness of fit  the worsening of parsimony (and therefore of interpretability) Starting with 𝑝 predictors, there exist 𝟐^𝒑 models each containing a different subset of the predictors. We need an automated approach to choose a smaller set of models to consider Three classical approaches:  Forward selection: start from the null model and adds one variable at each step  Backward selection: start from full model and exclude one variable at step (p  How well does the model fit the data? We can use the RSE (Residual Standard Error) that measures the lack of fit of the model to the data It is an absolute measure (measured on units of 𝑌)  or the R square statistic (coefficient of determination): To determine what is a good value of 𝑅2 can be difficult and depends on the application. Use of the model: We can use it for the description and interpretation but also fort the prediction of future value (prediction in a strict sense), of a value between other two values (interpolation) and estimation of a missing value (imputation). At the end we can use the model for simulation and control (reverse and not regression) or for stability studies.  Given a set of predictor values, what response value should we predict, and how accurate is our prediction? We must distinguish: the prediction of the expected value of 𝑌 associated with a given value of 𝑋 and the prediction of a single value of 𝑌 associated with a given value of 𝑋. Associated to the model there are some uncertainties:  this inaccuracy is related to the reducible error, To measure how close 𝑌^ is to 𝑓(𝑋), we can compute a confidence interval for 𝒇(𝑿) (𝑓 (𝑋) the expected value 𝐸(𝑌|𝑋) of the dependent variable)  assuming a linear model for 𝑓 𝑋 is an approximation, so there is a model bias (another source of reducible error)  even if we knew the true 𝑓 𝑋 (so the true parameters), 𝑌 cannot be predicted perfectly because of the random error 𝜖 in the model (irreducible error)

Slide 14: Xsouth Xwest 1 1 0 2 1 0 3 0 1 4 0 0 β 0 : average balance for individuals from the East β 0 + β 1 : average balance for individuals from the South β 1 : difference in the average balance between individuals from the South versus the East β 0 + β 2 : average balance for individuals from the West β 2 : difference in the average balance between individuals from the West versus the East. The choice of the reference category is arbitrary. The final predictions for each group will be the same regardless of this choice. However, estimates and their p-values do depend on the coding scheme. Rather than rely on individual coefficients, we can use F-test for all predictors, testing:

The fourth person is from East, beacuse he is not from South and neither from West (referred to upper table). Xsouth Xwest Xeast 1 1 0 0 2 1 0 0 3 0 1 0 4 0 0 1 Attention to the problem of multicollinearity, in this case if we add the column of 1 of the intercepts there is a problem with multicollinearity, so we must not include that column.

  1. CATEGORICAL PREDICTORS This dummy variable approach can be used when incorporating both quantitative and qualitative predictors. Example: we want to regress Balance and Income and Student. We create a dummy for Student and then fit a multiple regression model using: Y = Balance X = Student and Income We will see how to investigate level effects, slope effect and mixed effects.
  2. INTERACTION TERM Including interaction terms allows us to remove the additivity assumption, stating that the association between a predictor Xj and the response Y does not depend on the values of the predictors. Example: Advertising Data Additivity: the effect on sales of increasing the TV advertising budget does not depend on the amount spent on radio, and vice versa.

3) NONLINEAR RELATIONSHIPS

We extend the linear model to accommodate nonlinear relationships, in order to remove the linearity assumption, stating that the relationship between the response and predictors is linear, that is the change in Y associated with one-unit increase in Xj is constant (does not depend on the value of Xj). Polynomial regression: includes polynomial functions of the predictors in the linear regression model. We still have a linear regression model, but it is able to incorporate nonlinear associations.

  1. If the true relationship between the response and the predictor is far from linear, all the conclusions we draw are not reliable and the prediction accuracy can be very low.

Residual plots (plot of residuals with respect to X or Y ) can help in

identifying nonlinearity. As already seen, the presence of pattern in the residual plot may indicate the presence of nonlinearity. If the residual plot indicates that there are non-linear associations in the data, then a simple approach is to include non-linear transformations of the predictors in the model. For example, log(X), (^) √ X and X^2. Other more advanced non-linear approaches can be proposed.

  1. Classical assumptions of the linear model include that the error terms, ϵ 1 , ϵ 2 , … , ϵn, are uncorrelated. If the error terms are correlated, the estimated standard errors will tend to underestimate the true standard errors. As a result, we can have too much confidence in our model. If the estimated SE are smaller than thay should be:
  • confidence and prediction intervals are narrower than thay should be, so a 95% interval estimator may have a much lower probability than 95% of containing the true value.
  • p-values will be lower than they should be, so we can erroneously conclude that a predictor is significant. Error terms are usually correlated in:
  • Time series
  • Spatial data One possible solution is to transform the response variable Y. For example, when variance of the error terms increase with