Suffolk University • Sawyer Business School

Regression: Predicting Numbers

What is a house worth? Linear regression as the interpretable baseline, coefficients in dollars, log targets, ridge and lasso, and the residual plot that tells you what the model is missing

Session 6 of 13 · Mon Oct 26
Module: Regression
150 Minutes
Mondays 5:00 PM
Hands-On Learning
01 // LEARNING OBJECTIVES

What You'll Learn Today

By the end of tonight you'll have both the concept and the working code — every objective maps to a cell you run yourself.

01

Fit and Read a Linear Regression

Coefficients are slopes in business units: $112 per square foot, $9,800 per garage bay. You'll learn to state them, to standardize them before comparing them, and to stop reading them as causes.

02

Pick the Right Error Metric

RMSE punishes big misses, MAE reports the typical miss, MAPE explodes near zero, R² tells you how much of the variance you explained. Which one you report depends on who is asking.

03

Regularize With Ridge, Lasso & Elastic Net

Eighty features, one thousand houses: the recipe for overfitting. Penalized regression shrinks coefficients — and lasso sets most of them to exactly zero, which is feature selection for free.

04

Diagnose With Residuals

Predicted vs. actual, residuals vs. fitted, and the fan shape that says 'take the log of the target.' The plots that separate a model that works from one that merely runs.

02 // SESSION AGENDA

Today's Journey

A business question, a dataset, a model — and the judgment to evaluate it.

5:00 PM - 5:20 PM

From Yes/No to How Much

20 minutes

Five sessions of yes/no; tonight a number. Classification predicts a label; regression predicts a number — a price, a demand, a delivery time, a lifetime value. Same lifecycle, different target, different metrics. The Ames housing data: 1,460 sales, 79 features, a median price of $163,000.

  • The baseline is the mean: predict $181K for every house, RMSE ≈ $74K. Every model must beat that
  • Sale price is right-skewed: a few $500K+ homes will dominate squared error unless we take the log
5:20 PM - 5:40 PM

One Feature, One Line

20 minutes

Price against living area. The least-squares line, the intercept, the slope, and what 'holding everything else fixed' means once we add a second feature. The whole of linear regression in one picture.

  • Slope: roughly $110 per square foot on this data — a number a realtor can use
  • R² ≈ 0.50 with one feature: half the variance explained by size alone
5:40 PM - 6:05 PM

Many Features, Many Units

25 minutes

Pipeline from Session 3, target = log(price), LinearRegression at the end. Coefficients now live on the log scale — a coefficient of 0.10 means roughly +10% price. Standardize to compare importance; never compare a per-square-foot slope to a per-garage-bay slope raw.

  • log target: errors become percentage errors, so a 5% miss on a $100K house counts the same as on a $500K house
  • Predict, then np.expm1 to get back to dollars before you report RMSE
6:05 PM - 6:15 PM

Break

10 minutes

Stretch, coffee, argue about what a garage is worth.

6:15 PM - 6:45 PM

Overfitting & Regularization

30 minutes

Add polynomial terms and watch train R² climb while test R² collapses — the Overfitting Explorer, now with real houses. Then RidgeCV, LassoCV, ElasticNetCV: one alpha, chosen by cross-validation, and the coefficient path that shows lasso switching features off one by one.

  • Ridge shrinks; lasso selects. Elastic net does both. Scale features first or the penalty is unfair
  • LassoCV keeps ~25 of 200+ one-hot columns on Ames: a model a client can read
6:45 PM - 7:15 PM

Residual Diagnostics & the Metric Menu

30 minutes

Residuals vs. fitted: a fan means heteroscedasticity, a curve means a missing nonlinearity, a cluster of big misses means a segment the model doesn't understand. Then the metric menu — RMSE, MAE, MAPE, R² — and a one-line rule for which to report to whom.

  • Report MAE to operations (typical miss), RMSE to risk (big misses matter), R² to statisticians, never MAPE near zero
  • Preview: HistGradientBoostingRegressor on the same pipeline drops RMSE by another 20% — Session 8
7:15 PM - 7:30 PM

Wrap-Up & Homework #3, Part 2

15 minutes

The regression template: pipeline → log target → regularized linear model → residual plots → metrics in business units. HW3 Part 2 is the Ames competition in miniature.

  • HW3 Part 2: a leak-proof Ames pipeline with ridge or lasso, due Mon Nov 16 together with the threshold part from Session 5
  • Next: decision trees and random forests — the first model that needs no scaling at all
FEATURED VIDEO

StatQuest — Ridge (L2) Regression

Why shrinking coefficients toward zero makes predictions better on new data.

FEATURED VIDEO

StatQuest — Lasso (L1) Regression

And why the L1 penalty switches features off entirely.

03 // INTERACTIVE RESOURCES

Tools & Learning Materials

Notebooks, readings, explorers, and the stories behind the methods.

Hands-On

Session 6 Notebook — Regression on Ames Housing

One-feature line, full pipeline with log target, RidgeCV / LassoCV / ElasticNetCV with coefficient paths, residual diagnostics, and every metric on the menu in dollars.

Open in Colab
Play

The Overfitting Explorer — Bias, Variance, and Noise

Tonight's polynomial demo as a living picture: drag the degree, watch test error turn back up, then add data and watch the wiggles get tamed.

Open the explorer
Interactive

MLU-Explain — Linear Regression

Least squares as a picture: drag points, watch the line and the residuals move, and see what R² actually measures.

Open the explainer
Interactive

Setosa — Ordinary Least Squares, Explained Visually

Drag the data and watch the squared errors — literally drawn as squares — shrink as the line finds its place.

Open the explainer
Reading

ISLP, Chapter 3 — Linear Regression (and 6.2 — Shrinkage Methods)

The definitive free chapter on simple and multiple regression, plus the ridge and lasso section. Skip the math you don't need; read every figure caption.

Read the chapters (free PDF)
Go Deeper

Kaggle — House Prices: Advanced Regression Techniques

The Ames data as a permanent Kaggle competition. Submit your HW3 predictions and see where a well-built linear model lands on the leaderboard — a warm-up for the midterm competition.

Open the competition
Reading

scikit-learn User Guide — Linear Models

OLS, Ridge, Lasso, ElasticNet, and their CV variants, with the cost functions written out. The place to check what alpha actually multiplies.

Open the guide
Story

Story: Zillow's $500M Lesson in Prediction Error

In 2021 Zillow shut its home-flipping unit after its pricing models overpaid at scale, writing down more than $500 million. The residual plot nobody looked at — and a reminder that a point prediction without an error bar is a bet.

Read the story
Video

StatQuest — Ridge, Lasso & Elastic Net Regression

Search the index for 'Ridge', 'Lasso', and 'Elastic Net' — three short videos that make the penalty geometry obvious. Also embedded on this page.

Watch on YouTube
Refresher

Refresher: Linear Regression, Basis Functions, Ridge & Lasso (ISOM 730 notebook)

Prof. Arslan's earlier notebook: simple regression, polynomial basis functions, and the ridge/lasso intuition on a small example. The slow version of tonight's middle hour. Hosted in the course repo — opens in Colab with one click.

Open in Colab
04 // HANDS-ON ACTIVITIES

Learning by Doing

Open the notebook and build it with us.

Activity 1

What Is a House Worth? Regularized Regression on Ames

1,460 house sales in Ames, Iowa, with 79 features. Build a leak-proof pipeline that predicts log(price), let LassoCV choose the penalty, and report the error in dollars a buyer would understand.

1

Frame it

Unit: one house. Target: sale price (modeled as log). Horizon: at listing. Decision: list price / offer price. Baseline: the mean price, RMSE ≈ $74K.

2

Reuse the pipeline

Session 3's ColumnTransformer, unchanged. Log-transform the target with np.log1p before fitting.

3

Let CV pick alpha

LassoCV(cv=5) at the end of the pipeline. Inspect how many coefficients survived and which features they are.

4

Report in dollars

Predict on the test set, np.expm1 the predictions, then RMSE and MAE in dollars. Plot residuals vs. fitted and describe the shape in one sentence.

python
import numpy as np
from sklearn.datasets import fetch_openml
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LassoCV
from sklearn.metrics import mean_absolute_error, root_mean_squared_error

ames = fetch_openml('house_prices', as_frame=True)
X, y = ames.data.drop(columns=['Id']), ames.target
X_tr, X_te, y_tr, y_te = train_test_split(X, y, test_size=0.2, random_state=835)

# prep = the Session 3 ColumnTransformer (impute+scale numeric, one-hot categorical)
model = Pipeline([('prep', prep), ('lasso', LassoCV(cv=5, random_state=835))])
model.fit(X_tr, np.log1p(y_tr))

pred = np.expm1(model.predict(X_te))
print(f'Baseline RMSE (predict the mean): ${root_mean_squared_error(y_te, np.full(len(y_te), y_tr.mean())):,.0f}')
print(f'Lasso RMSE: ${root_mean_squared_error(y_te, pred):,.0f}   MAE: ${mean_absolute_error(y_te, pred):,.0f}')

coef = model.named_steps['lasso'].coef_
print(f'alpha chosen: {model.named_steps["lasso"].alpha_:.4f}, non-zero coefficients: {(coef != 0).sum()} of {len(coef)}')

Look at which features lasso kept. Overall quality, living area, neighborhood dummies, year built — the list reads like a realtor's checklist, which is the point: a regularized linear model is the most explainable strong model you will ever ship. Then look at the residual plot: the biggest misses are the most expensive houses. The model knows less about a $450K house because it has seen fewer of them — and that is exactly the segment where a mistake costs the most.

05 // KEY TAKEAWAYS

What to Remember

A linear coefficient is a slope in business units, holding other features fixed — not a cause, and not comparable across features until you standardize.

Ridge shrinks, lasso selects. Choose alpha by cross-validation, scale features first, and remember that a lasso model with 25 surviving features is one a client can read.

Metrics are for audiences: MAE for operations, RMSE when big misses hurt, R² for fit, MAPE never near zero. And always look at the residual plot — the fan shape is the log transform asking to be applied.

06 // HOMEWORK

Before Next Session

Complete these before next Monday — they are the practice that makes the next session land.

Homework #3, Part 2 + Competition Due Mon Nov 16, 11:59 PM, on Canvas, in the same notebook as Part 1 (the threshold on your HW2 credit model). Build a leak-proof Ames pipeline in Colab: ColumnTransformer preprocessing, log(price) target, and your choice of RidgeCV, LassoCV, or ElasticNetCV. Report test RMSE and MAE in dollars against the mean baseline, plot residuals vs. fitted, and write one paragraph naming the segment of houses your model gets most wrong and why. Bonus (+5%): submit your predictions to the Kaggle House Prices competition and include your public leaderboard score. Competition: your team of 2–3 should be formed on Kaggle with at least one submission by Mon Nov 2 — the same night Milestone 1 of the final project (your problem and dataset, one paragraph) is due on Canvas. The leaderboard closes Mon Nov 9, 4:30 PM.
07 // PRACTICE

Test Yourself

Exam-style questions for the ideas in this session — Regression & Regularization. Every wrong answer names the misconception behind it.

Q13 A $9,800 coefficient on garage spaces. What it says — and what it doesn't. Q14 Five errors, one big miss. Compute MAE and RMSE and see them disagree. Q15 Residuals that fan out from $8K stores to $2M stores. The classic fix. Q16 176 of 200 coefficients are exactly zero. Only one penalty can do that. Q17 Two models, RMSE and R² on the table. Do the metrics agree? Q18 A 10-unit miss shows up as 500% error. MAPE's dirty secret.

All of Regression →

Coming Next

Session 7: Decision Trees & Random Forests

How a tree splits, why it overfits, and how bagging hundreds of decorrelated trees fixes it. Out-of-bag scores, permutation importance, and the first model that needs no scaling at all.

Decision TreesRandom ForestsFeature Importance