1/193
Bullet pointed information is important or was emphasized in the lecture
Seven stages of data science?
Question → Data → Descriptive → Exploratory → Modeling → Interpretation → Presentation
Supervised learning
Learning from labeled input–output pairs (X,Y).
Independent variables (X)
Predictor inputs or features used to estimate the target.
Dependent variable (Y)
Response, label, or target to be predicted or explained.
What is regression?
Modeling a dependent outcome using one or more predictors.
Typical target for linear regression
Continuous numerical value, such as house price or traffic volume.
Y = β₀ + β₁X + ε
Regression intercept β₀
Expected fitted Y when all predictors equal 0.
Linear regression slope β₁
Change in fitted Y per unit X, other predictors held fixed.
Unobserved error ε
Part of Y not described by the systematic regression function.
Y = β₀ + ΣβⱼXⱼ + ε
Multiple: many X, one Y; multivariate: two or more Y jointly.
“Holding others constant”
Interpret a coefficient conditional on the other model predictors.
Y = Xβ + ε; fitted values Ŷ = Xβ̂.
Intercept in matrix X
A column of ones whose coefficient is the intercept.
Row and column of design matrix
Row = observation; column = predictor (including intercept column).
Σ[(xᵢ−x̄)(yᵢ−ȳ)]/(n−1)
Positive covariance
Two variables tend to rise together.
Negative covariance
As one variable rises, the other tends to fall.
Sample variance formula
s² = Σ(xᵢ−x̄)²/(n−1)
r = Cov(X,Y)/(sₓsᵧ), from −1 to +1.
Interpret r = +1
Perfect positive linear association.
Interpret r = −1
Perfect negative linear association.
Interpret r ≈ 0
Little linear association; a nonlinear relation may still exist.
Confounding or coincidence can produce associations.
β̂₁ = Cov(X,Y)/Var(X)
β̂₀ = ȳ − β̂₁x̄
L8 subway/rent: sample covariance
−7.25; distance and rent are negatively associated.
L8 subway/rent: Pearson r
Approximately −0.926 (strong negative linear association).
L8 subway/rent fitted line
Ŷ = 32.7 − 2.9X; Y measured in hundreds of dollars.
eᵢ = yᵢ − ŷᵢ (actual minus predicted).
Positive residual means…
The model underpredicted the outcome.
Minimize SSE = Σ(yᵢ − ŷᵢ)².
Why square errors in OLS?
Prevents cancellation; penalizes large errors more heavily.
How are basic OLS coefficients derived?
Differentiate sum of squared errors and solve normal equations.
β̂₁ = Σ[(xᵢ−x̄)(yᵢ−ȳ)]/Σ(xᵢ−x̄)²
β̂ = (XᵀX)⁻¹XᵀY, if XᵀX invertible.
One predictor is an exact linear combination of others.
Chosen model captures the systematic X–Y association adequately.
What should a useful residual plot look like?
Random scatter around zero without clear pattern or changing spread.
Strong overlap among predictors makes individual coefficients unstable.
Variance inflation of a coefficient due to other predictors.
How check for multicollinearity?
Correlation matrix or variance inflation factor (VIF).
Limits of linear regression
Sensitive to outliers; may miss nonlinear patterns and unstable under collinearity.
Choose parameters making the observed data most probable.
Independent, normally distributed, constant-variance errors.
MLE of heads probability: 8 heads / 10 tosses
0.80.
Likelihood
How compatible observed outcomes are with a parameterized model.
Log-likelihood
Natural log of likelihood; higher is better on same observations.
Baseline using no explanatory predictors.
Compare LL −85 vs. −120
−85 is higher; it fits those same observations better.
SST = Σ(yᵢ − ȳ)².
SSE = Σ(yᵢ − ŷᵢ)².
R² = 1 − SSE/SST.
Meaning of training R²=.70
Approximately 70% of sample outcome variation explained by fitted model.
Can test R² be negative?
Yes; model can predict worse than a mean-only reference.
1 − (1−R²)(n−1)/(n−p−1); p excludes intercept.
Why adjusted R²?
Discourages adding predictors that barely improve in-sample fit.
L8 traffic example R² and adjusted R²
R²≈0.711; adjusted R²≈0.518 (n=6, p=2).
MAE = Σ|yᵢ−ŷᵢ|/n.
MSE = Σ(yᵢ−ŷᵢ)²/n.
RMSE = √MSE (same units as target).
MAPE = 100·Σ| (yᵢ−ŷᵢ)/yᵢ |/n.
Which error metric punishes large mistakes more?
RMSE/MSE, because errors are squared.
Division by zero; near-zero actuals make it unstable.
L8 traffic metric example results
MAE=2.4; MSE=6.8; RMSE≈2.61; MAPE=10.4%.
Training fit differs from performance on unseen data.
Why compare against a baseline?
Check whether a fitted model improves on a simple reference prediction.
H₀: βⱼ=0; H₁: βⱼ≠0.
t = β̂ⱼ / SE(β̂ⱼ).
Under H₀ and assumptions, chance of a result at least as extreme.
Interpret a 95% coefficient confidence interval
Range of plausible coefficient values under repeated-sampling framework.
Two-sided coefficient p-value <.05.
H₀: β₁=…=βₚ=0 (all slopes jointly zero).
Predictors collectively improve fit relative to intercept-only model.
No; predictive association is not a causal effect.
L8 house-price example coefficient size
+$120 per ft²; +$5,000 per bedroom; +$8,000 per location point.
L8 house-price output fit statistics
R²=.900; adjusted R²=.895; F=168; overall p<.001.
Classification predicts a category; regression predicts a continuous value.
A prediction task with exactly two classes (0 and 1).
Predict among three or more mutually exclusive classes.
Its predictions can be negative or exceed 1.
z = β₀ + β₁X₁ + … + βₚXₚ.
p = P(Y=1|X) = 1/(1 + e^(−z)).
Sigmoid when z=0
p=0.5.
How does z relate to p?
z>0 ⇒ p>.5; z<0 ⇒ p<.5.
p≥.5 → class 1; p<.5 → class 0.
To trade missed positives against false alarms using validation.
L9 transit example z=.5 produces…
p≈.622, or 62.2% chance of transit use.
L=−[y ln(p) + (1−y) ln(1−p)].
L=−ln(p).
L=−ln(1−p).
Average log loss
Mean of individual binary cross-entropy losses.
What does log loss punish most?
Confident wrong probabilities, much more than confident correct ones.
If y=1, p=.1, log loss is…
About 2.303 (large).
Maximizing likelihood is equivalent to minimizing log loss.
Gradient descent
Iteratively update coefficients toward lower loss using the gradient.
Does logistic regression first fit OLS?
No; coefficients are estimated directly, usually via numerical MLE.
Probability p
Proportionate chance of an event from 0 to 1.
Odds = p/(1−p).