Machine Learning

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play

1/76

encourage image

There are no tags or description

Looks like no tags are added yet.

77 Terms

1
New cards

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.

2
New cards

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.

3
New cards

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.

4
New cards

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.

5
New cards

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.

6
New cards

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.

7
New cards

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.

8
New cards

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.

9
New cards

What is mean-square prediction error (MSPE)?

MSPE = E[(y0 - y0_hat)^2] = var(u0) + var(y0_hat) + [bias(y0_hat)]^2.

10
New cards

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.

11
New cards

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.

12
New cards

What does MSPE reduce to if the estimators are unbiased?

The variance of the prediction error: var(u0) + var(y0_hat).

13
New cards

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.

14
New cards

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.

15
New cards

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.

16
New cards

When is OLS prone to overfitting?

When the number of x's (K) is large relative to the sample size (N).

17
New cards

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.

18
New cards

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.

19
New cards

Write the formula for adjusted R-squared.

R-bar^2 = 1 - [SSE/(N - K - 1)] / [SST/(N - 1)].

20
New cards

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).

21
New cards

How does adjusted R-squared matter for prediction?

Because it penalizes useless variables, it discourages overfitting, whereas R^2 always favors adding more variables.

22
New cards

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.

23
New cards

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.

24
New cards

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.

25
New cards

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.

26
New cards

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.

27
New cards

What is the difference between regression and classification problems?

Regression problems predict a continuous (quantitative) outcome; classification problems predict a categorical outcome.

28
New cards

Where does regression fit in the ML landscape?

Squarely in supervised learning; MLers often call prediction of quantitative outcomes a "regression problem."

29
New cards

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).

30
New cards

What is the optimal level of model complexity?

The level that minimizes the out-of-sample MSPE.

31
New cards

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.

32
New cards

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.

33
New cards

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).

34
New cards

How many folds are commonly used in cross-validation?

Ten is a common choice (the cv.glmnet default is M = 10).

35
New cards

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.

36
New cards

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.

37
New cards

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.

38
New cards

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.

39
New cards

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.

40
New cards

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.

41
New cards

When is LASSO particularly appealing?

For sparse models where only a small share of the variables are expected to have non-zero coefficients.

42
New cards

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.

43
New cards

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.

44
New cards

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.

45
New cards

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.

46
New cards

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.

47
New cards

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).

48
New cards

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.

49
New cards

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).

50
New cards

Which R function automates LASSO cross-validation?

cv.glmnet (defaults: 100 lambda values and 10 folds).

51
New cards

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.

52
New cards

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.

53
New cards

Why set a random seed when splitting the sample?

To ensure the random split (and results) can be replicated.

54
New cards

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.

55
New cards

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."

56
New cards

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.

57
New cards

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.

58
New cards

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.

59
New cards

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.

60
New cards

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.

61
New cards

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.

62
New cards

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.

63
New cards

What are the two popular choices for G in binary response models?

Logistic CDF (logit model) and standard normal CDF Phi(z) (probit model).

64
New cards

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).

65
New cards

How are logistic regressions estimated?

By maximum likelihood: the MLEs are the betas that maximize the log-likelihood, computed numerically (in R, with glm).

66
New cards

Write the logit log-likelihood for one observation.

log L = y log G(b0 + xb) + (1 - y) log[1 - G(b0 + xb)].

67
New cards

How do you estimate a logit in R?

glm(formula, family = binomial(link = logit), data). Use predict(…, type = "response") to get predicted probabilities.

68
New cards

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.

69
New cards

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.

70
New cards

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 + …).

71
New cards

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.

72
New cards

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.

73
New cards

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.

74
New cards

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.

75
New cards

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.

76
New cards

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]).

77
New cards

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.