1 of 17

Source: xkcd.com/1725

2 of 17

Lecture 30

Least Squares

3 of 17

Announcements

  • Homework 8 is due tomorrow November 10 @ 10 AM
  • No lecture Wednesday November 11 (holiday)
  • Project 2 is out
    • Checkpoint is due on Friday, November 13 @ 5 PM
    • Entire Project is due Friday, November 20 @ 5 PM

4 of 17

Human Tech

Futures

Fall 2026

Tu 11/10, 4 pm, 1420 Gateway

David Bates

On the Crisis of Decision in the Age of Artificial Intelligence

​

Tu 11/17, 4 pm, 820 Social Sciences Building

Mona Sloane

Predicted: How AI is Restructuring Social Life

​

W 11/18, 2 pm, 310 Sutardja Dai Hall

First Encounters with AI: Writers on Writing (Panel)

​

Tu 12/8, 4 pm, 1420 Gateway

Marion Fourcade

The Ordinal Society

5 of 17

Human Tech

Futures

Fall 2026

Human Tech Futures (HTF) centers human experience in a rapidly changing technological world.

​

HTF researchers and students explore how AI and other technologies are embedded in and transform society, how data and algorithms shape human life, and how computational methods open new pathways into culture and human understanding.

​

HTF advances research and teaching at the frontiers of societal impact and human experience. We work across disciplines to contribute to liveable futures across social-technical divides.

​

6 of 17

Freshman-Sophomore Seminars

Small seminar format for lower-division students

​

CS 39: Technology, Society, and Power

  • Manuel Sabin and Lisa Yan
  • Thursdays 3-5pm
  • 2 units P/NP, lots of reading discussion
  • Apply today via class notes!

7 of 17

Linear Regression

8 of 17

Prediction

Goal: Predict y using x

Examples:

  • Predict # hospital beds available using air pollution
  • Predict house prices using house size
  • Predict # app users using # app downloads

9 of 17

Linear Regression Estimate

Goal: Predict y using x

​

To find the regression estimate of y:

  • Convert the given x to standard units
  • Multiply by r
  • That’s the regression estimate of y, but:
    • It’s in standard units
    • So convert it back to the original units of y

10 of 17

Regression Line

Standard Units

(0, 0)

1

r

Original Units

(Average x,� Average y)

SD x

r * SD y

11 of 17

Slope and Intercept (in original units)

estimate of y = slope * x + intercept

12 of 17

Discussion Question

Suppose we use linear regression to predict candy prices (in dollars) from sugar content (in grams). What are the units of each of the following?

  • r
  • The slope of the regression line
  • The intercept of the regression line

13 of 17

Least Squares

(Demo)

14 of 17

Error in Estimation

  • error = actual value − estimate

​

  • Typically, some errors are positive and some negative

​

  • To measure the rough size of the errors
    • square the errors to eliminate cancellation
    • take the mean of the squared errors
    • take the square root to fix the units
    • root mean square error (rmse)

(Demo)

15 of 17

Least Squares Line

  • Minimizes the root mean squared error (rmse) among all lines

​

  • Equivalently, minimizes the mean squared error (mse) among all lines

​

  • Names:
    • “Best fit” line
    • Least squares line
    • Regression line

16 of 17

Numerical Optimization

  • Numerical minimization is approximate but effective
  • Lots of machine learning uses numerical minimization
  • If the function mse(a, b)returns the mse of estimation using the line “estimate = ax + b”,
    • then minimize(mse)returns array [a₀, b₀]
    • a₀ is the slope and b₀ the intercept of the line that minimizes the mse among lines with arbitrary slope a and arbitrary intercept b (that is, among all lines)

(Demo)

17 of 17

Non-Linear Regression

(Demo)

FOR NEXT TIME