Linear Regression
(Reading: Ch 13)
(Slides adapted from Sandrine Dudoit and Joey Gonzalez)
UC Berkeley Data 100 Summer 2019
Sam Lau
Learning goals:
Announcements
Last Time
Modeling
Making Predictions
Models
Prediction
Input data
Recipe to compute the prediction
Two model weights
The Constant Model
Model Loss
Constant Model Loss
Modeling is Estimation in New Clothes
The Modeling Pipeline
We choose what goes in the blue boxes!
Input Data
Model
Predictions
Loss Function
Loss
Model Weight(s)
Fit a model by finding weights that minimize loss.
Minimizing sample loss approximates minimizing population loss.
The Modeling Recipe
Model | Loss Function | Technique Name |
| | Least squares linear regression |
| | Lasso regression |
| | Ridge regression |
| | Least absolute deviations |
| | Logistic regression |
Linear Models
Using Our Data
Simple Linear Model
Simple Linear Model
Skipping Ahead
Multivariable Linear Model
Intuition
Using Matrix Multiplication
Bolded letters means vector or matrix.
More Notation!
Your turn: Write the matrix expression that computes a vector with a fitted linear model’s predictions for all sample points.
Your Turn
Write the matrix expression that computes a vector with a fitted linear model’s predictions for all sample points.
Your Turn
Write the matrix expression that computes the average MSE loss for all data points (this is a scalar!).
Your Turn
Write the matrix expression that computes the average MSE loss for all data points (this is a scalar!).
Using matrix notation takes a lot of practice to get used to, but the results are worth it. Always check your dimensions!
Fitting a Linear Model
The Normal Equation
What are the matrix shapes in these expressions?
The Abnormal Equation
Demo: Predicting MPGs
Feature Engineering
(moved to Wed lecture)
Linear Models Level Up
Adding Features
(Demo)
Polynomial Regression
Categorical Features
One-Hot Encoding
One-Hot Encoding
One Hot Problem
Not invertible ^
=
+
+
Weight Interpretation
0
3
3
3
3
0
0
0
=
Drop it Like it’s Hot
Features feat. More Features
Summary