Intro to prediction and Ordinary Least Squares

STAT 20: Introduction to Probability and Statistics

Warmup
10:00

For each of the following scenarios identify:

  • the target variable \(Y\) and its type
  • (time permitting, the features \(X_j\), their types, and how many they are (\(q\)))
  • whether it’s a regression or a classification task

Secenario A

  • Amazon sets the price for a specific book, dependent on the book’s weight and whether it is hardback or paperback.

Careful!! This is a Causality question. “What would happen if I were to set the price of the book at some value \(x\)?”

Secenario B

  • Abebooks guesses the time it’ll take to sell a specific book, based on the price it can freely set, the book’s weight and whether it is hardback or paperback.

Careful again! This is a Causal Prediction question. As a prediction problem, it’s a regression because time should be modeled as a continuous variable. But it’s also causal because again your’re wondering “What would happen if I were to set the price of the book at some value \(x\)?”

Secenario C

  • Ebay guesses the final sale price for a specific book, based on the initial bid price the seller has set, the book’s weight and whether it is hardback or paperback.

Finally! This is a straight-up Prediction task. It’s a Regression because sale price should be modeled as a continuous variable.

Secenario D

  • A Waymo engineer is working on a model to determine whether the self-driving car is seeing a real car or a reflection of a car.

This is a Prediction task. It’s a Classification task, because whether the car is real should be modeled as a discrete (Bernoulli) variable.

Secenario E

  • A marine biologist is trying to guess the nose-to-tail length of the typical manatee in the waters off the coast of Florida, broken down by sex and age groups.

You fell for it again! This is not a Prediction task. It’s a Generalization task, because they’re estimating various population parameters (conditional means). These are hidden, non observable quantities.

Secenario F

  • The Weather Channel predicts tomorrow’s temperature based on historical data, tomorrow’s expected weather conditions and yesterday’s temperature.

This is a Prediction task. It’s a Regression task, because temperature is modeled as a continuous variable. Careful, the historical data isn’t a feature, it’s either the sample used to fit the model or some other miscellaneous info that will help with writinf down the model.

Secenario G

  • The UCB Admissions office has to predict whether a student will accept its admission offer or not based on the student’s high school and their intended major.

This is a Prediction task. It’s a Classification task, because whether the car is real should be modeled as a binary (Bernoulli) variable.

Secenario H

  • A philologist examines a 2nd century BCE papyrus from Egypt, full of holes, and written in Coptic. They make a guess about the missing letters in the holes, based on the surrounding words, the dating, the geographic origin of the papyrus.

Careful! This is a Prediction task. Althout this thing was written 2200 years ago, we are still “predicting” the value of an unseen random variable (the missing letter). It’s a Classification task, because a letter from the Coptic alphabet is a nominal categorical variable.

Which is better?

  • Large MSE or small MSE?

Small. MSE measures error!

Concept Question 1. Sample Mean Squared Error (MSE)
01:00

  • Imagine the following sample (\(n=3\)) with true values of \(Y\) and the predictions from some model \(\hat{Y}_{\mbox{model}}\). The units of \(Y\) are kilograms.
Y Ŷ
1 2.3 2.8
2 −1.6 −1.2
3 4.3 3.6
  • Calculate the sample MSE of the model. \(\widehat{\mbox{MSE}} =?\)

\(\widehat{\mbox{MSE}} = \frac1{3} \left((-0.5 \, kg)^2 +(-0.4 \, kg)^2 +(0.7 \, kg)^2 \right) = 0.3 \, kg^2\)

Concept Question 2.

  • Which of these two features \(X_j\) will yield the better prediction \(\hat{Y}\), based on the sample we collected and plotted below?

\(X_1\) on the left seems more strongly associated with \(Y\) than \(X_2\) is.

Concept Question 3

  • If your model \(\hat{Y}\) is awesome, what will be the typical size of the residual in either case?

Roughly 3-ish kg using \(X_1\) and roughly 7-ish kg using \(X_2\) depending on where you look on the \(x\)-axis.

Concept Question 4

  • Here is a function f.
f <- function(x, y) {
  y*(x + 3) 
}

What will the following line of code return?

f(3,5)

Break

05:00

Worksheet: Method of Least Squares

40:00