1/76
Looks like no tags are added yet.
Why is regression appropriate for prediction?
One justification for regression is that the population regression function (PRF) is the best linear predictor of y given the x's: the coefficients solve the population least-squares problem, minimizing the mean squared error.
What is the prediction goal in the house price example?
Build a model that accurately predicts house prices (no causal analysis, just prediction) using data from the 2011 American Housing Survey.
What was the analysis sample in the house price example?
Detached, suburban, owner-occupied homes of no more than 5,000 square feet from the 2011 AHS (a subset of the Mullainathan and Spiess 2017 sample), N = 18,236.
Why do we care about out-of-sample (OOS) prediction?
A model's usefulness is judged by how well it predicts new data it was not estimated on, not by how well it fits the sample used to estimate it.
How is the OOS prediction error defined?
e0_hat = y0 - y0_hat, where y0 is an out-of-sample outcome and y0_hat = b0_hat + b1_hat x1^0 + … + bK_hat xK^0 is the regression prediction.
What is the best prediction of an OOS outcome y0?
The conditional expectation E(y0 | x1^0, …, xK^0), whose regression estimate is y0_hat.
What are the two sources of variation in the prediction error?
Model uncertainty (the error term u0, with variance sigma^2) and estimation error (sampling error in the beta_hat's, var(y0_hat)). So var(e0_hat) = sigma^2 + var(y0_hat) if the estimators are unbiased.
How do you construct a 95% prediction interval for y0?
y0_hat +/- z(.025) * se(e0_hat), where se(e0_hat) = sqrt(var(e0_hat)) and z(.025) = 1.96.
What is mean-square prediction error (MSPE)?
MSPE = E[(y0 - y0_hat)^2] = var(u0) + var(y0_hat) + [bias(y0_hat)]^2.
Why is MSPE a good measure of prediction accuracy?
It captures the tradeoff between bias and variance, so a slightly biased estimator with much lower variance can predict better than an unbiased one.
Why don't we limit ourselves to unbiased estimators for prediction?
There may be a favorable tradeoff between bias and variance: accepting some bias can reduce variance enough to lower the MSPE.
What does MSPE reduce to if the estimators are unbiased?
The variance of the prediction error: var(u0) + var(y0_hat).
Which estimator dominates in the N(0,1) vs. N(.5, .5^2) illustration if the true mean is 0?
The biased estimator N(.5, .5^2) can have lower MSE than the unbiased N(0,1) because its variance is much smaller (MSE = variance + bias^2), illustrating the bias-variance tradeoff.
What is overfitting?
A model that fits the sample too closely, with low bias but high variance: its estimated coefficients reflect noise and idiosyncratic features of the sample more than the underlying relationship.
Why is overfitting a problem for out-of-sample prediction?
An overfit model captures noise in the training sample, so it predicts new data poorly (high variance, high OOS MSPE) even though its in-sample fit is excellent.
When is OLS prone to overfitting?
When the number of x's (K) is large relative to the sample size (N).
What does "regularize" a model mean?
Add a penalty to the estimation problem that taxes model complexity (e.g., shrinks coefficients), trading a little in-sample fit for lower variance and better out-of-sample prediction.
What is the difference between R-squared and adjusted R-squared?
R^2 = 1 - SSE/SST never falls when variables are added, so it encourages overfitting. Adjusted R^2 = 1 - [SSE/(N-K-1)] / [SST/(N-1)] uses degrees-of-freedom corrections, so it penalizes variables with little explanatory power.
Write the formula for adjusted R-squared.
R-bar^2 = 1 - [SSE/(N - K - 1)] / [SST/(N - 1)].
When does adjusted R-squared rise after adding a variable?
If and only if the added variable's estimated coefficient has a t statistic greater than 1 (in absolute value).
How does adjusted R-squared matter for prediction?
Because it penalizes useless variables, it discourages overfitting, whereas R^2 always favors adding more variables.
What is a shrinkage estimator?
An estimator that adds a penalty on the size of each beta_k to the OLS minimization problem, shrinking the coefficient estimates toward zero and taxing model complexity.
Why does shrinking the coefficients help prediction?
Without a penalty, coefficients are free to chase noise in the sample (overfitting). Shrinkage reduces variance, shrinking y_hat toward the mean of y.
How do modern ML methods differ from the variable selection methods in BUSN 4000?
Instead of choosing variables with F/t tests, adjusted R^2, forward/backward/stepwise selection, ML builds a bias-variance tradeoff directly into the estimation problem through a penalty.
What is machine (statistical) learning?
Data-driven algorithms that improve with experience to solve problems. In this course it focuses on prediction rather than causal inference.
What is the difference between supervised and unsupervised learning?
Supervised: both an outcome and (many) predictors are observed. Unsupervised: no outcome; the goal is cluster analysis and pattern recognition.
What is the difference between regression and classification problems?
Regression problems predict a continuous (quantitative) outcome; classification problems predict a categorical outcome.
Where does regression fit in the ML landscape?
Squarely in supervised learning; MLers often call prediction of quantitative outcomes a "regression problem."
What are the two steps of model selection in ML?
(1) Choose the best in-sample loss-minimizing function for a given level of complexity. (2) Choose the optimal level of complexity through empirical tuning (e.g., cross-validation).
What is the optimal level of model complexity?
The level that minimizes the out-of-sample MSPE.
How do we estimate the OOS MSPE if we cannot observe it?
Randomly split the data into training and testing samples; the test sample plays the role of OOS data and is held out until the end. Cross-validation on the training data tunes complexity.
What are the main steps in cross-validation?
Randomly divide the training sample into M equal folds; hold one fold out for validation; estimate the model on the other M-1 folds; compute MSPE on the validation fold; repeat for each fold; compute CV(M) = (1/M) sum of the MSPE_m.
Write the cross-validation criterion.
CV(M) = (1/M) * sum over m=1..M of MSPE_m, the average of the M validation-fold MSPEs. Select the candidate model with the smallest CV(M).
How many folds are commonly used in cross-validation?
Ten is a common choice (the cv.glmnet default is M = 10).
What is the role of the training, validation, and test samples?
Training: estimate the model. Validation (CV folds): tune complexity. Test: held out until the end to give an honest estimate of out-of-sample performance.
What is LASSO?
Least absolute shrinkage and selection operator: a regularized regression that minimizes SSE + lambda * sum of |beta_k|, adding an absolute-value penalty to the OLS objective.
Write the LASSO objective function.
SSE + lambda * sum over k=1..K of |beta_k|, where lambda >= 0 is the tuning parameter governing the tradeoff between in-sample fit and shrinkage.
What does the tuning parameter lambda do?
It sets the strength of the penalty. Small lambda: close to OLS (noise can overwhelm signal). Large lambda: heavy shrinkage (too much removed, signal and noise). lambda = 0 gives OLS.
How does LASSO differ from conventional regression (OLS)?
OLS minimizes SSE only (unbiased, but can overfit); LASSO adds a penalty that shrinks coefficients toward zero, introduces bias, lowers variance, and sets some coefficients exactly to zero.
Why is LASSO a variable selection method?
For sufficiently large lambda, the absolute-value penalty forces some coefficients to be exactly zero, effectively dropping those variables. Appealing for sparse models.
When is LASSO particularly appealing?
For sparse models where only a small share of the variables are expected to have non-zero coefficients.
Why must you standardize the x's before LASSO?
Shrinkage estimators are not invariant to the scale of the x's; standardizing (x - mean)/sd puts all covariates on the same scale. glmnet does this for you.
What does the model look like after standardization?
The outcome is demeaned and there is no intercept: y - ybar = b1 x1_tilde + … + bK xK_tilde + u. Predictions are y0_hat = ybar + sum of b_k_hat (x_k^0 - xbar_k)/sd_k.
Which R function estimates LASSO and how does it solve it?
glmnet (package glmnet), which solves the minimization numerically with a coordinate descent algorithm since there is no simple closed-form LASSO estimator for more than one regressor.
What does the glmnet alpha argument do?
It is the elastic net mixing parameter: alpha = 1 is LASSO (default), alpha = 0 is Ridge, and values between 0 and 1 combine LASSO and Ridge.
What is Ridge regression?
Another shrinkage procedure (alpha = 0 in glmnet) that penalizes the sizes of the coefficients but, unlike LASSO, does not set them exactly to zero.
What does the LASSO coefficient path plot show?
How each estimated coefficient shrinks toward zero (and some become exactly zero) as lambda increases (plotted against -log lambda).
What is deviance and how does it relate to R-squared?
Deviance = -2 log L (L the likelihood). Residual deviance plays the role of SSE and null deviance the role of SST, so percent deviance explained is like R-squared.
How does cross-validation work for LASSO?
For each lambda in a grid (default J = 100 values), split the training sample into M = 10 folds, estimate on M-1 folds, compute validation MSPE, average to get CV(M), and pick the lambda that minimizes CV(M).
Which R function automates LASSO cross-validation?
cv.glmnet (defaults: 100 lambda values and 10 folds).
What did the LASSO cross-validation find for house prices?
Minimum CV(M) MSPE estimate of 0.4744 at lambda = 0.0023, with 52 nonzero coefficients out of 85.
How were the house price data split into training and testing samples?
70/30 using initial_split with set.seed(123): N = 18,236, training N = 12,765, testing N = 5,471, with K = 36 covariates before creating dummies.
Why set a random seed when splitting the sample?
To ensure the random split (and results) can be replicated.
What are the steps in applying LASSO to the house price problem?
Identify features; split into training/testing; define the initial specification for the CEF; apply LASSO to the training sample; plot coefficient estimates by lambda; cross-validate and plot CV(M); identify the best-performing model by MSPE; compare LASSO and OLS predictions.
How did LASSO compare with OLS on the test data?
LASSO had a slightly lower test-sample MSPE (0.54295 vs. 0.54394): LASSO wins "by a hair."
How do you obtain the OLS coefficients from a glmnet LASSO fit?
Set lambda to 0 (s = 0 with exact = TRUE): LASSO with lambda = 0 is OLS.
Why not use the estimated LASSO coefficients to make inferences?
There are no standard errors, regularization introduces bias, and variable selection can vary by fold, so the coefficients are basically meaningless for inference about the data-generating process.
What does model.matrix do in the house price code?
Creates the design matrix according to the model specification and automatically converts factor variables into dummies.
Why is the intercept suppressed (~ 0 + …) in the design matrix?
glmnet standardizes the x's and demeans y, so it handles the intercept itself and the matrix should not include a constant column.
What is the main problem with the linear probability model (LPM) for prediction?
Predicted probabilities can fall outside the unit interval [0, 1], so they cannot be interpreted as probabilities.
What is logistic regression and how is it used in prediction?
A true probability model for a binary outcome: P(y=1|x) = G(b0 + xb) with G the logistic CDF, so predictions lie between 0 and 1. It is preferred for classification problems.
Write the logistic function.
G(z) = Lambda(z) = exp(z)/[1 + exp(z)], a CDF that maps the index b0 + xb onto the unit interval.
What are the two popular choices for G in binary response models?
Logistic CDF (logit model) and standard normal CDF Phi(z) (probit model).
What is the latent variable model for binary outcomes?
y* = b0 + xb + u is an unobserved propensity; we observe y = 1 if y* > 0 and 0 otherwise, so P(y=1|x) = G(b0 + xb).
How are logistic regressions estimated?
By maximum likelihood: the MLEs are the betas that maximize the log-likelihood, computed numerically (in R, with glm).
Write the logit log-likelihood for one observation.
log L = y log G(b0 + xb) + (1 - y) log[1 - G(b0 + xb)].
How do you estimate a logit in R?
glm(formula, family = binomial(link = logit), data). Use predict(…, type = "response") to get predicted probabilities.
Are logit coefficients the partial effects?
No. The model is nonlinear, so beta_k is not the partial effect (though its sign gives the direction). The partial effect depends on the x values.
What is the partial effect of a continuous x_k in a logit model?
dp(x)/dx_k = g(b0 + xb) * beta_k, where g(z) = dG(z)/dz.
What is the partial effect of a dummy variable in a logit model?
The difference in predicted probabilities with the dummy equal to 1 and 0: G(b0 + b1 + b2x2 + …) - G(b0 + b2x2 + …).
What are average partial effects (APEs)?
Partial effects averaged over the sample (also called average marginal effects, AMEs). In R they are computed with the margins function.
Compare the logit coefficient and the APE for education in the Mroz data.
Logit coefficient 0.221 versus APE (AME) 0.0395. The APE is close to the LPM coefficient (0.038) and is the number to interpret as a change in probability.
What happened when the LPM and logit predicted labor force participation for two very different women?
LPM predictions were -0.41 and 1.04 (impossible as probabilities); the logit predicted 0.0052 and 0.9500, bounded between 0 and 1.
What does the Mroz example predict?
Female labor-force participation (inlf = 1 if in the labor force in 1975) from nwifeinc, educ, exper, age, kids under 6, and kids 6-18, using 753 women from the PSID.
Why is the test statistic labeled z instead of t in the margins output?
Inference relies on an asymptotic argument (standard normal), not an exact t distribution.
Why can you still use OLS with a binary outcome in causal work?
E(y|x) = P(y=1|x) is still the CEF, so OLS consistently estimates the partial effects on the response probability. The problem is mainly prediction (probabilities outside [0,1]).
How do you evaluate a classifier with a fit measure if you use LPM?
Report the percentage correctly predicted using y_tilde = 1 if y_hat >= .5 and 0 otherwise.