Skip to content
Expedify
Regression I — predicting a number

Module · Framing

Framing a regression problem — when the answer is a number

Lesson 1 of 8 · 8 min

A marketing lead has a budget and three channels to spend it across. One question has to be answered before the quarter starts. what will we sell if we spend it like this?

Not is this campaign working — that is a yes-or-no question. Not which channel is best — that is a ranking. The question is a number, in units or in revenue, and it has to be a specific one, because a plan gets approved against it.

That is regression: predicting a quantity. It is the oldest thing in machine learning and still the most used in business. Most questions a company has to answer come with a unit attached: rupees, units, days, leads.

A regression answers with a quantity. A classifier answers with a bucket.

Almost every supervised model you will meet answers one of two questions. The difference is the shape of the answer rather than the algorithm.

The same data can support both. What decides which you are doing is the question you asked.

The answer is

Regression
a quantity on a scale
Classification
one of a fixed set of labels

Asked as

Regression
how much, how many, how long
Classification
which one, will it, is this

In go-to-market

Regression
What will this campaign return? What will this deal close at? How many leads next month?
Classification
Will this customer churn? Is this lead qualified? Which segment is this?

Wrong by

Regression
an amount — off by 4,000 units
Classification
a class — you said churn, they stayed

Judged with

Regression
RMSE, MAE,
Classification
accuracy, precision, recall, AUC

The line is not always where you expect. How likely is this lead to convert? sounds like classification, and the model underneath usually is. But the sales team acts on a score between 0 and 1, which is a number. So the question to ask is what does the person receiving this act on.

Name the decision before you choose the model

This is the part most courses skip, and it is the part that decides whether your model is ever used.

Nobody wants a predicted sales figure. They want to know what to spend, where to move budget, which accounts to call first. A prediction earns its place only by changing one of those. So the honest order of work runs backwards from where beginners start:

  1. Name the decision. Somebody, at some moment, has to choose something. Who, and when?
  2. Name the number that would change it. That is your target — and it fixes the unit you predict in.
  3. Name what is known at that moment. Only facts available before the decision can be inputs. Everything else is cheating, and it is the most common way a model that scored beautifully turns out to be worthless.
  4. Then, and only then, choose a model. It is the least interesting step.

Step 3 is the one that bites. A model that predicts campaign revenue from the orders the campaign produced will look superb and tell you nothing. Orders are not known when the budget is set. This has a name, leakage, and it gets a lesson of its own later in the track.

Regression needs a target, examples, and features known before the decision

Three things. If any is missing, the question is not yet a regression problem:

  • A measurable target. Written down, in a unit, for periods that already happened.
  • Examples where you know the answer. Enough of them, and representative of what you will face next. This is the constraint that quietly kills most ideas.
  • Features known before the moment of decision. See above. A rule about timing, not about data quality.

If any of those three is missing, the question is not yet a regression problem.

One dataset: 200 markets, three channels, and a sales figure

Everything in this path is built on one dataset and one decision. Each row is a market: a city, a region, a territory. A budget was split across three channels there, and a sales figure came back.

advertising-media-mix.csv
200 rowsDownload
salesthousands of unitswhat the market sold — this is the target
tv_spend$ thousandsTV budget in that market
radio_spend$ thousandsradio budget
newspaper_spend$ thousandsnewspaper budget

200 markets, 0 missing values. Budgets in $ thousands, sales in thousands of units — worth remembering, because a coefficient means nothing until you know its units.

Four columns is small, and that is deliberate. Every column is a line somebody controls, and the target is what the business is judged on. The decision is real too. TV already takes 73% of the average market's budget and newspaper takes 15%. By the end of this path you will be able to say whether that split is defensible.

Sales range from 1.6 to 27.0 thousand units across markets, with the middle of the pack at 12.9. Explaining that spread is the job.

A line gives you base sales and incremental sales per $1,000

When you fit a straight line to sales against spend, the line has two parts, and both have names that predate machine learning by decades:

  • The intercept — base sales. What the market sells when media spend is zero. Brand, distribution, habit, word of mouth. Not nothing, and not marketing's to claim.
  • The slope — incremental sales per unit of spend. The extra sales one more $1,000 buys. This is the number budget arguments are actually about, and it is the honest version of return on ad spend.

A regression splits an outcome into what would have happened anyway and what the spending bought. That is the split that decides next quarter's plan.

Both names predate machine learning by decades, and finance already argues in them.

Eight lessons, one dataset, one budget decision

Eight lessons, one dataset, and a question at the end of each that the next one answers:

  1. This lesson — the question is a number, and the decision comes first.
  2. Look before you fit. What the data says before any model touches it.
  3. The line. Least squares, base sales, and what a slope claims in units per $1,000.
  4. Is it any good? R², RMSE, and the residual plot that tells you more than either.
  5. More than one thing matters. All three channels at once — and one of them stops working.
  6. Which features earn their place. Selection, and comparing models honestly.
  7. The honest number. Why the score you just quoted is optimistic, and what to quote instead.
  8. A forecast someone can act on. Back to the budget we started from.

One idea to carry into the next lesson. A regression predicts the average outcome for a market like this one — not the outcome. Every strength and every failure in the next seven lessons follows from that sentence.