A very brief introduction to machine learning for

39 8 0
A very brief introduction to machine learning for

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

A Very Brief Introduction to Machine Learning for Regression A Colin Cameron Univ of California- Davis Abstract: These slides attempt to demystify machine learning The slides cover standard machine learning methods such as k-fold cross-validation, lasso, regression trees and random forests The slides conclude with some recent econometrics research that incorporates machine learning methods in causal models estimated using observational data Presented at the third Statistical Methodology in the Social Sciences Conference University of California - Davis, 2017 More at http://cameron.econ.ucdavis.edu/e240f/machinelearning.html October 27, 2017 A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning October The27, slides 2017cover standard / 39 Introduction Introduction The goal is prediction Machine learning means that no stuctural model is given I I I Instead the machine is given an algorithm and existing data These train the machine to come up with a prediction model This model is then used to make predictions given new data Various methods guard against over…tting the existing data There are many, many algorithms I a given algorithm may work well for one type of data and poorly for other types Forming data to input can be an art in itself (data carpentry) I e.g what features to use for facial recognition What could go wrong? I I correlation does not imply causation social science models can help here A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning October The27, slides 2017cover standard / 39 Introduction Overview Terminology Cross-validation Regression (Supervised learning for continuous y ) Subset selection of regressors Shrinkage methods: ridge, lasso, LAR Dimension reduction: PCA and partial LS High-dimensional data Nonlinear models in including neural networks Regression trees, bagging, random forests and boosting Classi…cation (categorical y ) Unsupervised learning (no y ) Causal inference with machine learning References A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning October The27, slides 2017cover standard / 39 Terminology Terminology Topic is called machine learning or statistical learning or data learning or data analytics where data may be big or small Supervised learning = Regression I I I We have both outcome y and regressors x Regression: y is continuous Classi…cation: y is categorical Unsupervised learning I I We have no outcome y - only several x Cluster Analysis: e.g determine …ve types of individuals given many psychometric measures These slides I focus on A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning October The27, slides 2017cover standard / 39 Terminology Terminology (continued) Machine learning methods guard against over…tting the data Consider two types of data sets I training data set (or estimation sample) F I used to …t a model test data set (or hold-out sample or validation set) F F additional data used to determine model goodness-of-…t a test observation (x0 , y0 ) is a previously unseen observation Models are created on and we use the model that does best on A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning October The27, slides 2017cover standard / 39 Cross Validation Cross Validation Goal: Predict y given p regressors x1 , , xp Criterion: use squared error loss (y I yb)2 some methods adapt to other loss functions Training data set: yields the prediction rule b f (x1 , , xp ) I e.g OLS yields yb = b β0 + b β1 x1 + +b β p xp Test data set: yields an estimate of the true prediction error I This is E [(y0 yb0 )2 ] for (y0 , x10 , , xp0 ) not in the training data set Note that we not use the training data set mean squared error I I MSE = n1 ∑ni=1 (yi ybi )2 because models over…t in sample (they target y not E [y jx1 , , xp ]) F e.g if p = n then R = and ∑ni=1 (yi ybi )2 = A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning October The27, slides 2017cover standard / 39 Cross Validation Bias-variance tradeoÔ 10 x 15 20 A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning October The27, slides 2017cover standard / 39 Cross Validation Stata Example D.g.p is quadratic with n = 40 Fit OLS polynomial of degree * Generate data: quadratic with n=40 (total) and n=20 (train) and n=20 (test) qui set obs 40 set seed 10101 gen x1 = _n - mod(_n+1,2) // x1 = 1 3 5 39 39 gen x2 = x1^2 gen x3 = x1^3 gen x4 = x1^4 gen dtrain = mod(_n,2)==1 // dtrain = 1 gen y = + 0.1*(x1-20)^2 + rnormal(0,10) reg y x1-x4, noheader y Coef x1 x2 x3 x4 _cons 4540487 -.437711 020571 -.0002477 37.91263 Std Err 3.347179 3399652 0127659 0001584 9.619719 t 0.14 -1.29 1.61 -1.56 3.94 P>|t| 0.893 0.206 0.116 0.127 0.000 [95% Conf Interval] -6.341085 -1.127877 -.0053452 -.0005692 18.38357 7.249183 2524551 0464871 0000738 57.4417 A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning October The27, slides 2017cover standard / 39 Cross Validation Predictions in training and test data sets Now …t to only training data (nTrain = 20) and plot predictions Quartic model predicts worse in test dataset (right panel) I I Training data (left): scatterplot and …tted curve (nTest = 20): Test data (right): scatter plot (diÔerent y ) and predictions (n = 20) 40 20 -20 -20 20 40 60 T est 60 T raining 10 y 20 x1 30 Fitted v alues 40 10 y 20 x1 30 40 Fitted v alues A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning October The27, slides 2017cover standard / 39 Cross Validation Single split-sample validation Fit polynomial of degree k on training data for k = 1, , I compute MSE ∑ (y ybi )2 for training data and test data i i Test MSE is lowest for quadratic I Training MSE is lowest for quartic due to over…tting * Split sample validation - training and test MSE for polynomials up to deg forvalues k = 1/4 { qui reg y x1-x`k' if dtrain==1 qui predict y`k'hat qui gen y`k'errorsq = (y`k'hat - y)^2 qui sum y`k'errorsq if dtrain == qui scalar mse`k'train = r(mean) qui sum y`k'errorsq if dtrain == qui scalar mse`k'test = r(mean) } di _n "MSE linear > "MSE quadratic > "MSE cubic > "MSE quartic Train = " mse1train Train = " mse2train " Train = " mse3train " Train = " mse4train " MSE MSE MSE MSE = = = = linear quadratic cubic quartic Train Train Train Train 252.32258 92.781786 87.577254 72.864095 Test Test Test Test = = = = " Test = " mse1test _n /// Test = " mse2test _n /// Test = " mse3test _n /// Test = " mse4test _n 412.98285 184.43114 208.24569 207.78885 A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning OctoberThe 27,slides 2017 cover10 standard / 39 Nonlinear Models Nonlinear Models Basis function models I I I I I I polynomial regression step functions regression splines smoothing splines, B-splines, wavelets polynomial is global while the others break range of x into pieces Other methods I I I local polynomial regression generalized additive models neural networks A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning OctoberThe 27,slides 2017 cover25 standard / 39 Nonlinear Models Neural Networks Neural Networks Neural network is a very rich parametric model for f (x) I I only parameters need to be estimated as usual guard against over…tting Consider a neural network with two layers I Y depends on m Z0 s (a hidden layer) that depend on p X0 s Z1 Zm T f (X) = g (α01 + X0 α1 ) v) e.g g (v ) = 1/(1 + e = g (α0m + X0 αm ) = β0 + ∑M m =1 βm Zm = h (T ) usually h(T ) = T So with above g ( ) and h( ) f (xi ) = β0 + ∑m =1 βm M 1 + exp( α0m xi0 αm ) We need to …nd the number M of hidden units and estimate the α0 s A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning OctoberThe 27,slides 2017 cover26 standard / 39 Nonlinear Models Neural Networks Neural Networks (continued) Minimize the sum of squared residuals but need a penalty on α0 s to avoid over…tting I I Since penalty is introduced standardize x s to (0,1) Best to have too many hidden units and then avoid over…t using penalty Neural nets are good for prediction I I especially in speech recognition, image recognition, but very di¢ cult (impossible) to interpret Deep learning uses nonlinear transformations such as neural networks I I deep nets are an improvement on original neural networks e.g led to great improvement of Google Translate A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning OctoberThe 27,slides 2017 cover27 standard / 39 Nonlinear Models Neural Networks OÔ-the-shelf software I I I converts e.g image or text to y and x to data input runs the deep net using stochastic gradient descent e.g CNTK (Microsoft), or Tensor‡ow (Google) or mxnet b Inference: neural net gives in-sample ybi = ψi (xi )0 β I e and se( β e ) so out-of-sample OLS regress yi on ψi (x) gives β A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning OctoberThe 27,slides 2017 cover28 standard / 39 Regression Trees Regression Trees Regression Trees sequentially split regressors x into regions that best predict y I e.g., …rst split is education < or > 12 and second split is on gender for education > 12 and third split is on age 55 or > 55 for male with education > 12 and could then re-split on education Then ybi = y¯R j is the average of y s in the region that xi falls in I with J blocks RSS = ∑Jj=1 ∑i 2R j (yi y¯R j )2 Need to determine both the regressor j to split and the split point s I I Each split is the one that reduces RSS the most Stop when e.g less than …ve observations in each region A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning OctoberThe 27,slides 2017 cover29 standard / 39 Regression Trees Example: annual earnings y depend on education, gender, age, A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning OctoberThe 27,slides 2017 cover30 standard / 39 Regression Trees Bagging, Random Forests and Boosting Trees not predict well due to high variance I I I e.g split data in two then can get quite diÔerent trees e.g rst split determines future splits called a greedy algorithm as does not consider future splits Bagging (bootstrap averaging) computes regression trees I I for many diÔerent samples obtained by bootstrap then average predictions across the trees Random forests use only a subset of the predictors in each bootstrap sample Boosting grows tree using information from previously grown trees I and is …t on a modi…ed version of the original data set Bagging and boosting are general methods (not just for trees) A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning OctoberThe 27,slides 2017 cover31 standard / 39 Classi…cation Methods Classi…cation Methods y s are now categorical (e.g binary if two categories) Use (0,1) loss function I if correct classi…cation and if missclassi…ed Methods I I I logistic regression, multinomial regression, k nearest neighbors linear and quadratic discriminant analysis support vector classi…ers and support vector machines A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning OctoberThe 27,slides 2017 cover32 standard / 39 Unsupervised Learning Unsupervised Learning Challenging area: no y , only X Principal components analysis Clustering Methods I I k means clustering hierarchical clustering A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning OctoberThe 27,slides 2017 cover33 standard / 39 Causal Inference with Machine Learning Causal Inference with Machine Learning Focus on causal estimation of a key parameter, such as an average marginal eÔect, after controlling for confounding factors For models with selection on observables (unconfoundedness) I I I e.g regression with controls or propensity score matches good controls makes this assumption more reasonable so use only use machine learning methods (notably lasso) to select best controls And for instrumental variables estimation with many possible instruments I I using a few instruments avoids many instruments problem use machine learning methods (notably lasso) to select best instruments But valid statistical inference needs to control for this data mining I currently active area of econometrics research A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning OctoberThe 27,slides 2017 cover34 standard / 39 Causal Inference with Machine Learning Commercial example is online website predicting quantity demand change from price change q (p ) = f (p ) + e (p ) where e (p ) is error I I naive machine learners will …t f (p ) well but dq (p )/dp = df (p )/dp + de (p )/dp Suppose y = g (x ) + ε where x is endogenous I I I I there are instruments E [εjz ] = R then π (z ) = E [y jz ] = E [g (x )jz ] = g (x )dF (x jz ) b (z ) and Fb (x jz ) use machine learner to get π then solve the above integral equation Easier for economists to use oÔ-the-shelf machine learners I than for machine learners to learn methods for endogeneity A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning OctoberThe 27,slides 2017 cover35 standard / 39 Big Data Big Data Hal Varian (2014), “Big Data: New Tricks for Econometrics”, JEP, Spring, 3-28 Tools for handling big data I …le system for …les split into large blocks across computers F I database management system to handle large amounts of data across many computers F I Sawzall (Google), Pig Computer language for parallel processing F I MapReduce (Google), Hadoop language for Mapreduce / Hadoop F I Bigtable (Google), Cassandra accessing and manipulating big data sets across many computers F I Google …le system (Google), Hadoop …le system Go (Google - open source) simpli…ed structured query language (SQL) for data enquiries F Dremel, Big Query (Google), Hive, Drill, Impala A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning OctoberThe 27,slides 2017 cover36 standard / 39 10 Conclusion 10 Conclusion Machine learning focuses on prediction I guarding for over…tting using validation or AIC/BIC Supervised learning predicts y given x I I usual regression minimizes MSE = bias2 + variance classi…cation minimizes (0,1) loss function Most popular machine learning method I deep neural nets Economists / econometricians adapt to causal inference using I I LASSO Random forests A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning OctoberThe 27,slides 2017 cover37 standard / 39 11 References 11 Book References http://cameron.econ.ucdavis.edu/e240f/machinelearning.html Next two books I used have free pdf and $25 softback Undergraduate / Masters level book I Gareth James, Daniela Witten, Trevor Hastie and Robert Tibsharani (2013), An Introduction to Statistical Learning: with Applications in R, Springer Masters / PhD level book I Trevor Hastie, Robert Tibsharani and Jerome Friedman (2009), The Elements of Statistical Learning: Data Mining, Inference and Prediction, Springer A recent book I Bradley Efron and Trevor Hastie (2016), Computer Age Statistical Inference: Algorithms, Evidence and Data Science, Cambridge University Press Interesting general audience book is Cathy O’Neil, Weapons of Math Destruction: How Big Data Increases Inequality and Threatens Democracy A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning OctoberThe 27,slides 2017 cover38 standard / 39 11 References Simpler Articles Hal Varian (2014), “Big Data: New Tricks for Econometrics”, Journal of Economic Perspectives, Spring, 3-28 Sendhil Mullainathan and J Spiess (2017), “Machine Learning: An Applied Econometric Approach”, Journal of Economic Perspectives, Spring, pp 87-106 A Belloni, V Chernozhukov and C Hansen (2014), “High-Dimensional Methods and Inference on Treatment and Structural EÔects in Economics, Journal of Economic Perspectives Spring, pp.29-50 Following are leaders in causal econometrics and machine learning I Victor Chernozhukov, Alex Belloni, Christian Hansen + coauthors F I use Lasso a lot SusanAthey and Guido Imbens F use random forests a lot A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning OctoberThe 27,slides 2017 cover39 standard / 39 ... econometricians adapt to causal inference using I I LASSO Random forests A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning OctoberThe... demystify machine learning October The27, slides 2017cover standard / 39 Terminology Terminology Topic is called machine learning or statistical learning or data learning or data analytics where data... A Colin Cameron Univ of California- Davis (Abstract: Brief TheseMachine slides attempt Learning to demystify machine learning OctoberThe 27,slides 2017 cover35 standard / 39 Big Data Big Data

Ngày đăng: 02/09/2021, 20:42

Mục lục

    Subset Selection of Regressors

    8. Causal Inference with Machine Learning

Tài liệu cùng người dùng

Tài liệu liên quan