NYU Intro to Datascience Cumulative Notcards Lectures 8-10

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

1/193

flashcard set

Earn XP

Description and Tags

Bullet pointed information is important or was emphasized in the lecture

194 Terms

1
New cards
  • Seven stages of data science?


Question → Data → Descriptive → Exploratory → Modeling → Interpretation → Presentation

2
New cards
  • Supervised learning


Learning from labeled input–output pairs (X,Y).

3
New cards

Independent variables (X)

Predictor inputs or features used to estimate the target.

4
New cards

Dependent variable (Y)

Response, label, or target to be predicted or explained.

5
New cards

What is regression?

Modeling a dependent outcome using one or more predictors.

6
New cards

Typical target for linear regression

Continuous numerical value, such as house price or traffic volume.

7
New cards
  • Simple linear regression equation

Y = β₀ + β₁X + ε

8
New cards

Regression intercept β₀

Expected fitted Y when all predictors equal 0.

9
New cards

Linear regression slope β₁

Change in fitted Y per unit X, other predictors held fixed.

10
New cards

Unobserved error ε

Part of Y not described by the systematic regression function.

11
New cards
  • Multiple linear regression equation

Y = β₀ + ΣβⱼXⱼ + ε

12
New cards
  • Multiple vs. multivariate regression

Multiple: many X, one Y; multivariate: two or more Y jointly.

13
New cards

“Holding others constant”

Interpret a coefficient conditional on the other model predictors.

14
New cards
  • Linear model matrix form

Y = Xβ + ε; fitted values Ŷ = Xβ̂.

15
New cards

Intercept in matrix X

A column of ones whose coefficient is the intercept.

16
New cards

Row and column of design matrix

Row = observation; column = predictor (including intercept column).

17
New cards
  • Sample covariance formula

Σ[(xᵢ−x̄)(yᵢ−ȳ)]/(n−1)

18
New cards

Positive covariance

Two variables tend to rise together.

19
New cards

Negative covariance

As one variable rises, the other tends to fall.

20
New cards

Sample variance formula

s² = Σ(xᵢ−x̄)²/(n−1)

21
New cards
  • Pearson correlation r

r = Cov(X,Y)/(sₓsᵧ), from −1 to +1.

22
New cards

Interpret r = +1

Perfect positive linear association.

23
New cards

Interpret r = −1

Perfect negative linear association.

24
New cards

Interpret r ≈ 0

Little linear association; a nonlinear relation may still exist.

25
New cards
  • Why doesn't correlation prove causation?

Confounding or coincidence can produce associations.

26
New cards
  • OLS simple slope from covariance

β̂₁ = Cov(X,Y)/Var(X)

27
New cards
  • OLS simple intercept equation

β̂₀ = ȳ − β̂₁x̄

28
New cards

L8 subway/rent: sample covariance

−7.25; distance and rent are negatively associated.

29
New cards

L8 subway/rent: Pearson r

Approximately −0.926 (strong negative linear association).

30
New cards

L8 subway/rent fitted line

Ŷ = 32.7 − 2.9X; Y measured in hundreds of dollars.

31
New cards
  • Residual formula

eᵢ = yᵢ − ŷᵢ (actual minus predicted).

32
New cards

Positive residual means…

The model underpredicted the outcome.

33
New cards
  • OLS objective

Minimize SSE = Σ(yᵢ − ŷᵢ)².

34
New cards

Why square errors in OLS?

Prevents cancellation; penalizes large errors more heavily.

35
New cards

How are basic OLS coefficients derived?

Differentiate sum of squared errors and solve normal equations.

36
New cards
  • Simple OLS slope formula

β̂₁ = Σ[(xᵢ−x̄)(yᵢ−ȳ)]/Σ(xᵢ−x̄)²

37
New cards
  • Multiple OLS matrix formula

β̂ = (XᵀX)⁻¹XᵀY, if XᵀX invertible.

38
New cards
  • Perfect multicollinearity

One predictor is an exact linear combination of others.

39
New cards
  • Linear regression functional-form assumption

Chosen model captures the systematic X–Y association adequately.

40
New cards

What should a useful residual plot look like?

Random scatter around zero without clear pattern or changing spread.

41
New cards
  • Multicollinearity

Strong overlap among predictors makes individual coefficients unstable.

42
New cards
  • Variance inflation factor (VIF)

Variance inflation of a coefficient due to other predictors.

43
New cards

How check for multicollinearity?

Correlation matrix or variance inflation factor (VIF).

44
New cards

Limits of linear regression

Sensitive to outliers; may miss nonlinear patterns and unstable under collinearity.

45
New cards
  • Maximum likelihood estimation (MLE)

Choose parameters making the observed data most probable.

46
New cards
  • When does Gaussian linear MLE equal OLS?

Independent, normally distributed, constant-variance errors.

47
New cards

MLE of heads probability: 8 heads / 10 tosses

0.80.

48
New cards

Likelihood

How compatible observed outcomes are with a parameterized model.

49
New cards

Log-likelihood

Natural log of likelihood; higher is better on same observations.

50
New cards
  • Null/intercept-only model

Baseline using no explanatory predictors.

51
New cards

Compare LL −85 vs. −120

−85 is higher; it fits those same observations better.

52
New cards
  • Total sum of squares (SST)

SST = Σ(yᵢ − ȳ)².

53
New cards
  • Residual sum of squares (SSE)

SSE = Σ(yᵢ − ŷᵢ)².

54
New cards
  • R² formula

R² = 1 − SSE/SST.

55
New cards

Meaning of training R²=.70

Approximately 70% of sample outcome variation explained by fitted model.

56
New cards

Can test R² be negative?

Yes; model can predict worse than a mean-only reference.

57
New cards
  • Adjusted R² formula

1 − (1−R²)(n−1)/(n−p−1); p excludes intercept.

58
New cards

Why adjusted R²?

Discourages adding predictors that barely improve in-sample fit.

59
New cards

L8 traffic example R² and adjusted R²

R²≈0.711; adjusted R²≈0.518 (n=6, p=2).

60
New cards
  • MAE formula

MAE = Σ|yᵢ−ŷᵢ|/n.

61
New cards
  • MSE formula

MSE = Σ(yᵢ−ŷᵢ)²/n.

62
New cards
  • RMSE formula

RMSE = √MSE (same units as target).

63
New cards
  • MAPE formula

MAPE = 100·Σ| (yᵢ−ŷᵢ)/yᵢ |/n.

64
New cards

Which error metric punishes large mistakes more?

RMSE/MSE, because errors are squared.

65
New cards
  • Why MAPE fails at actual Y=0

Division by zero; near-zero actuals make it unstable.

66
New cards

L8 traffic metric example results

MAE=2.4; MSE=6.8; RMSE≈2.61; MAPE=10.4%.

67
New cards
  • In-sample fit vs. out-of-sample prediction

Training fit differs from performance on unseen data.

68
New cards

Why compare against a baseline?

Check whether a fitted model improves on a simple reference prediction.

69
New cards
  • Coefficient t-test null and alternative

H₀: βⱼ=0; H₁: βⱼ≠0.

70
New cards
  • t-statistic for coefficient vs 0

t = β̂ⱼ / SE(β̂ⱼ).

71
New cards
  • Meaning of p-value

Under H₀ and assumptions, chance of a result at least as extreme.

72
New cards

Interpret a 95% coefficient confidence interval

Range of plausible coefficient values under repeated-sampling framework.

73
New cards
  • 95% CI excludes zero: usually indicates…

Two-sided coefficient p-value <.05.

74
New cards
  • Overall regression F-test null

H₀: β₁=…=βₚ=0 (all slopes jointly zero).

75
New cards
  • What does a significant overall F-test tell you?

Predictors collectively improve fit relative to intercept-only model.

76
New cards
  • Does good prediction establish causality?

No; predictive association is not a causal effect.

77
New cards

L8 house-price example coefficient size

+$120 per ft²; +$5,000 per bedroom; +$8,000 per location point.

78
New cards

L8 house-price output fit statistics

R²=.900; adjusted R²=.895; F=168; overall p<.001.

79
New cards
  • Classification vs. regression

Classification predicts a category; regression predicts a continuous value.

80
New cards
  • Binary classification

A prediction task with exactly two classes (0 and 1).

81
New cards
  • Multiclass classification

Predict among three or more mutually exclusive classes.

82
New cards
  • Why not OLS for class probability?

Its predictions can be negative or exceed 1.

83
New cards
  • Logistic linear predictor

z = β₀ + β₁X₁ + … + βₚXₚ.

84
New cards
  • Sigmoid / logistic probability

p = P(Y=1|X) = 1/(1 + e^(−z)).

85
New cards

Sigmoid when z=0

p=0.5.

86
New cards

How does z relate to p?

z>0 ⇒ p>.5; z<0 ⇒ p<.5.

87
New cards
  • Default binary threshold rule

p≥.5 → class 1; p<.5 → class 0.

88
New cards
  • Why change decision threshold?

To trade missed positives against false alarms using validation.

89
New cards

L9 transit example z=.5 produces…

p≈.622, or 62.2% chance of transit use.

90
New cards
  • Binary log-loss for one case

L=−[y ln(p) + (1−y) ln(1−p)].

91
New cards
  • Log loss when y=1

L=−ln(p).

92
New cards
  • Log loss when y=0

L=−ln(1−p).

93
New cards

Average log loss

Mean of individual binary cross-entropy losses.

94
New cards

What does log loss punish most?

Confident wrong probabilities, much more than confident correct ones.

95
New cards

If y=1, p=.1, log loss is…

About 2.303 (large).

96
New cards
  • Logistic MLE and log loss

Maximizing likelihood is equivalent to minimizing log loss.

97
New cards

Gradient descent

Iteratively update coefficients toward lower loss using the gradient.

98
New cards

Does logistic regression first fit OLS?

No; coefficients are estimated directly, usually via numerical MLE.

99
New cards

Probability p

Proportionate chance of an event from 0 to 1.

100
New cards
  • Odds from probability

Odds = p/(1−p).