Welcome to Week 8

Part 1

Midterm wrap-up & peer reviews

Part 2

What is machine learning, and what problems can it solve?

Part 3

What does it take to do ML well? A case study to see it in action

Midterm Wrap-Up

Midterm: Your Honest Feedback

I want to hear what worked and what didn’t. Your feedback shapes how I run this project next time.

👍 Keep

What did you like? What should I definitely keep?

👎 Didn’t work

What was frustrating, confusing, or not worth the effort?

🔧 Change

If you could change one thing about the project, what would it be?


No wrong answers, and nothing you say here affects your grade.

Peer Reviews Due Thursday

Due by end of day Thursday

Review your assigned classmate’s project and give specific, constructive feedback on:

  • Data analysis approach
  • Visualization effectiveness
  • Business recommendations
  • Code organization and clarity

Questions about the peer review process?

From Describing to Predicting

For Seven Weeks You’ve Asked…

“What happened?”

Today we start asking:
“What will likely happen next?”

Be the Algorithm

Homes sold over the past three months

Month House Sq. ft. Beds Sale price
Jul A 1,000 2 $120,000
Jul B 1,400 3 $165,000
Aug C 1,800 3 $210,000
Aug D 2,200 4 $255,000
Sep E 2,600 4 $300,000

Weeks 1–7: summarize & aggregate what already happened

Homes going up for sale next month

Month House Sq. ft. Beds Sale price
Oct G 1,600 3 ?
Oct H 3,000 5 ?

Now: predict what we expect to happen

What do you think houses G and H will sell for? How did you come up with your guesses?

What You Just Did Is Machine Learning

📋 Examples

Houses A–E, with known sale prices

➜

🧠 Find the pattern

“About $110K more per 1,000 sq. ft.”

➜

🔮 Apply it

Predict prices for new houses G & H

Machine learning: algorithms that learn patterns from examples, then apply those patterns to new data.

Key Vocabulary

sq_ft bedrooms neighborhood sale_price
1,000 2 Midtown $120,000
1,400 3 Oakley $165,000
1,800 3 Hyde Park $210,000
1,600 3 Oakley ?
3,000 5 Hyde Park ?
  • Features (X): the input columns we know — sq_ft, bedrooms, neighborhood
  • Target (y): the column we want to predict — sale_price
  • Training data: rows where we know the target
  • New data: rows where the target is unknown — that’s where the model predicts

Now Let the Computer Play

Same game, real data: 1,460 houses from Ames, Iowa.

import pandas as pd
from sklearn.linear_model import LinearRegression

ames = pd.read_csv("../data/ames_clean.csv")

model = LinearRegression()
model.fit(ames[["GrLivArea"]], ames["SalePrice"])     # learn from examples

new_houses = pd.DataFrame({"GrLivArea": [1600, 3000]})
model.predict(new_houses)                             # predict new cases
array([189977.60020181, 339960.10275396])

Tip

fit() on examples, predict() on new cases. Weeks 9–14 are about doing this well: choosing the right model, measuring how good it is, and avoiding the traps we’ll cover today.

Same Data, Two Kinds of Questions

Remember the Complete Journey grocery data? The same tables can answer very different questions:

📊 EDA questions: What happened?

Which departments drove the most sales last quarter?

How does spending differ across income levels?

Which coupons were redeemed most often?

What were our busiest days of the week?

🔮 ML questions: What will likely happen next?

How much will each household spend next month?

Which households are likely to stop shopping with us?

Will this household redeem the coupon we send them?

What will be our busiest day and time next week?

Why this matters

More and more organizations are investing in ML because it tells them what to expect next, so they can make important decisions now based on those expectations.

ML Is Already All Around You

What Problems Can ML Solve?

Three Questions ML Answers

📈 How much? How many?

Regression — predict a number

What will this house sell for?

How many units will we sell next week?

How much will this customer spend next year?

🏷️ Which one? Yes or no?

Classification — predict a category

Is this transaction fraud?

Will this customer cancel?

Is this review positive, negative, or neutral?

👥 What groups exist?

Clustering — discover structure

What types of shoppers do we have?

Which stores behave alike?

What viewing patterns exist?

Note

Regression & classification are supervised: we have a target to learn from (an “answer key”). Clustering is unsupervised: no target, the algorithm finds groups on its own.

Choosing the Right Tool

What do you need to know?

↓

What happened?

Summarize the past

↓

📊 EDA

groupby, charts, dashboards

↓

What will happen?

There’s a known outcome to learn from. Is it a number or a category?

↓

📈 Regression

number

🏷️ Classification

category

↓

What groups exist?

No outcome to learn from

↓

👥 Clustering

discover structure

Rapid Fire: EDA or ML?

For each scenario, hold up fingers to vote:

☝️ 1

EDA

Describe what happened

✌️ 2

Regression

Predict a number

🤟 3

Classification

Predict a category

🖖 4

Clustering

Discover groups


You’ve got about 10 seconds per scenario. Use the flowchart!

Scenario 1 of 8

A retailer wants to know which regions had the highest sales last quarter.

1 EDA · 2 Regression · 3 Classification · 4 Clustering

☝️ EDA — it’s a summary of the past. One groupby answers it; no model needed.

Scenario 2 of 8

A hospital wants to flag which patients are likely to be readmitted within 30 days of discharge.

1 EDA · 2 Regression · 3 Classification · 4 Clustering

🤟 Classification — predict a yes/no outcome for each new patient, learned from past patients.

Scenario 3 of 8

A streaming service wants to discover the different types of viewing behavior among its subscribers.

1 EDA · 2 Regression · 3 Classification · 4 Clustering

🖖 Clustering — there’s no target; we want the data to reveal the groups.

Scenario 4 of 8

A retailer wants to predict how much revenue each customer will generate next year.

1 EDA · 2 Regression · 3 Classification · 4 Clustering

✌️ Regression — the outcome is a dollar amount for each customer.

Scenario 5 of 8

A marketing team wants a dashboard showing customer demographics by region.

1 EDA · 2 Regression · 3 Classification · 4 Clustering

☝️ EDA — summarizing and visualizing what’s already in the data. Using ML here would be overkill.

Scenario 6 of 8

A bank needs to automatically flag fraudulent credit card transactions as they happen.

1 EDA · 2 Regression · 3 Classification · 4 Clustering

🤟 Classification — fraud / not fraud, learned from past transactions that were confirmed as fraud.

Scenario 7 of 8

A grocery chain wants to forecast how many gallons of milk each store will sell next week.

1 EDA · 2 Regression · 3 Classification · 4 Clustering

✌️ Regression — the outcome is a quantity.

Scenario 8 of 8

Kroger wants to find shoppers with similar baskets so it can tailor coupons to each group.

1 EDA · 2 Regression · 3 Classification · 4 Clustering

🖖 Clustering — nobody has labeled the “types” of shoppers; the algorithm discovers them.

What Does ML Require?

When ML Goes Wrong

🏠 Zillow Offers (2021)

Zillow used its home-price predictions to buy houses directly. When the market shifted, it overpaid for thousands of homes, wrote down $300M+, and shut the business down.

A prediction isn’t a business plan: define the decision, the risk, and how you’ll measure success.

📄 Amazon Recruiting Tool (2018)

Trained on 10 years of résumés, mostly from men. It learned to downgrade résumés from women, picking up on clues like “women’s chess club” or all-women’s colleges. Amazon scrapped it.

Biased history in → biased predictions out.

🤒 Google Flu Trends (2013)

Predicted flu levels from search queries. During the 2012–13 season it estimated roughly double the actual peak. Search behavior had changed; the model hadn’t.

Your data must reflect the world you’re predicting, and keep reflecting it.

🛒 Target Pregnancy Model (2012)

A model inferred pregnancy from shopping baskets and mailed baby coupons, reportedly before one teen’s family knew.

Being able to predict something doesn’t mean you should act on it.

Notice a Pattern?

None of these failed because of a bad algorithm.

They failed on problem framing, data, and ethics: decisions made before anyone trained a model.

The ML Project Canvas

Eight questions to answer before you write any modeling code:

① Is ML the right tool?

Could a rule, query, or dashboard do the job?

② Problem statement

Predict ___ for ___ within ___ so that ___ can ___.

③ Target & unit

What exactly is y? One row = one what?

④ Action

Who uses the prediction, and what do they do differently?

⑤ Success metrics

A model metric and a business metric

⑥ Data readiness

Sources, quality issues, and how we’ll split train/test

⑦ Leakage risks

What wouldn’t be known at prediction time?

⑧ Ethics

Fairness, privacy, interpretability

We’ll fill it in for a case study today, and you’ll put it to work in Thursday’s lab.

Case Study: StreamFlix

The Request

StreamFlix: 2M+ subscribers, losing 5% per month (~$15M+ annual impact). The VP of Customer Success emails you:


“Our customer churn is killing us! Can you build an AI model to predict which customers will cancel so we can save them? We need this ASAP for next quarter’s retention campaign.”


What’s vague or risky about this request?

① Is ML the Right Tool?

What’s the simplest thing that could work?

“Call everyone whose viewing time dropped 50%+ last month.”

Tip

If a simple rule catches most churners, you might not need ML. If it doesn’t, that rule becomes your baseline: the model has to beat it to be worth building.

②–④ The Problem Statement


Template:

Predict target for unit within time horizon so that who can action.


StreamFlix:

Predict whether a subscriber will cancel for each active subscriber within the next 30 days so that the retention team can contact the 1,000 highest-risk subscribers each month with targeted offers.

⑤ Success Metrics: You Need Two

🎯 Model metric

Of the 1,000 subscribers we flag each month, at least 80% would actually have cancelled.

Is the model finding the right people?

The technical term for this is precision.

💰 Business metric

Monthly churn drops from 5% → 4%.

Is the business better off?

Warning

A model can ace the model metric and still miss the business metric. For example, if it finds the right people but the offers don’t change their minds.

⑥ What’s Wrong With This Data?

A sample of StreamFlix’s subscriber table:

customer_id plan signup_date avg_weekly_hrs state churned
1001 Premium 2022-03-14 12.5 OH No
1002 premium 03/22/2022 NaN Ohio No
1003 Basic 2023-07-01 -2.0 KY Yes
1004 PREM 2027-01-15 8.0 IN 1
1002 premium 03/22/2022 NaN Ohio No
1005 Standard 2021-11-30 0.0 OH yes

With a neighbor: find as many problems as you can.

⑥ What We Found

customer_id plan signup_date avg_weekly_hrs state churned
1001 Premium 2022-03-14 12.5 OH No
1002 premium 03/22/2022 NaN Ohio No
1003 Basic 2023-07-01 -2.0 KY Yes
1004 PREM 2027-01-15 8.0 IN 1
1002 premium 03/22/2022 NaN Ohio No
1005 Standard 2021-11-30 0.0? OH yes

Duplicate rows · inconsistent labels · mixed date formats · a future date · missing & impossible values · a target coded 4 different ways · is 0.0 real or missing?

Tip

Your EDA toolkit is the data readiness check: .duplicated(), .isna().sum(), .value_counts(), .describe(), pd.to_datetime()

⑦ Don’t Let the Answer Sneak In

Imagine studying with the answer key printed on the back of every question: you’d ace the test and learn nothing.

The same thing happens when your training data contains information about the result you’re trying to predict:

customer_id avg_weekly_hrs months_subscribed final_bill_issued churned
1001 12.5 26 No No
1003 2.0 4 Yes Yes
1005 0.5 9 Yes Yes

The model “learns” that a final bill = a cancellation and scores nearly 100% in testing. But a final bill only exists after someone cancels, so when it’s time to predict, the model has nothing to go on.

⑦ Data Leakage

Data leakage: training on information you won’t have when you actually make the prediction.

Known before Feb 1

🔮 Predict on Feb 1

Feb 1 – Mar 2: who cancels?

✅ Safe: known before the prediction

Viewing hours over the last 90 days

Months subscribed

Failed payments in the last 3 months

❌ Leak: only known after

Final bill amount

Support tickets filed after cancelling

account_status = “cancelled”

Ask of every feature: “Would I actually have this value on Feb 1?”

⑦ The Leakage Smell Test

🚨 If your model hits 99% accuracy,
suspect leakage before you celebrate.

Common culprits: columns updated after the outcome, status fields, and anything created because of the outcome.

⑧ Ethics: The Headline Test

It’s one year from now, and StreamFlix’s churn model is in the news. What’s the headline you’d hate to read?

⚖️ Fairness

“Streaming giant’s best discounts skip customers in low-income zip codes”

Safeguard: audit model results across customer groups.

🔒 Privacy

“StreamFlix mined kids’ profiles and location data to target offers”

Safeguard: use only the data the problem needs.

🔍 Interpretability

“‘The algorithm decided’: customers can’t learn why neighbors got better deals”

Safeguard: make sure the retention team can explain why someone was flagged.

StreamFlix: The Completed Canvas

① Right tool?

Yes, if it beats the “viewing dropped 50%” rule

② Problem

Predict cancellation within 30 days so retention can contact the top 1,000 each month

③ Target & unit

y = cancelled in next 30 days (yes/no); one row = one subscriber

④ Action

Retention team sends targeted offers to the 1,000 highest-risk subscribers

⑤ Metrics

Model: 80%+ of flagged subscribers truly at risk. Business: churn 5% → 4%

⑥ Data

Viewing, billing, support data; clean labels & dates; time-based split

⑦ Leakage

Only data known before the prediction date; no status, final bill, or offer flags

⑧ Ethics

Audit by group, minimize data, explain flags to the team

From a vague, rushed request to a plan you can actually build, before writing a single line of model code.

Wrap-Up

This Week in Three Cards

🧠 What ML is

Algorithms that learn patterns from examples and apply them to new data.

fit() on examples → predict() on new cases

❓ What it can answer

How much? → regression

Which one? → classification

What groups? → clustering

What happened? → still EDA!

🧱 What it requires

A clear problem and action, two kinds of success metrics, ready data with no leakage, and an ethics check.

The 8-box canvas

Thursday’s Lab: Put It Into Practice

You’ll use today’s thought process on a real business problem:

👥 Team up

Work in teams on a business scenario

➜

🔍 Analyze

Assess whether it’s ready to be an ML project, box by box

➜

🎤 Present

Make your case to the class in lab

➜

✍️ Refine & submit

Use the feedback to polish it for homework

Tip

The 8-box canvas is your road map: a strong case answers every box, especially ①, ⑦, and ⑧.

Looking Ahead

📅 By Thursday

Peer reviews due end of day

Read chapters 19 & 20

🧪 Thursday Lab

Team ML readiness case: present in lab, then refine & submit as homework

🔜 Week 9

Your first real models: correlation & linear regression in Python


Questions?