Framing a problem for machine learning

Turn a business question into a prediction target, a unit of analysis and a success metric.

Lesson 2 of 6610 minBeginner

You will learn to

  • Define a target and the unit of prediction
  • Choose a task type from the question
  • Write a success criterion before modeling

Before this lesson

Intuition

Most failed machine learning projects do not fail because of the algorithm. They fail because the question was never turned into something a model can answer. "Reduce churn" is a goal. A model needs something much more concrete: which row, which column to predict, and how we will know it worked.

Think of a doctor. "Make the patient healthier" is a goal. "Predict which patients will be readmitted within 30 days so that a nurse can call them" is a prediction problem: it names the patient (the unit), the outcome (readmission within 30 days), the time window, and the action that follows. Framing is the work of getting from the first sentence to the second.

Five things must be written down before you train anything:

  1. The decision. What will someone do differently because of the prediction? If nothing changes, the model has no value.
  2. The unit of prediction. What does one row represent: a customer, an order, a customer in a given quarter?
  3. The target. The exact outcome, with its time window, in a form you can measure from past data.
  4. The task type. Classification, regression, forecasting, clustering or anomaly detection.
  5. The success criterion. The result at which the model is worth using, stated in terms of the decision.

Picture it

1DecisionWho gets aretention offer?2UnitOne customer perquarter3TargetLeaves within 90days: yes or no4TaskClassification5SuccessNet value abovedoing nothing
The five things to write down before modeling. Each step narrows the one before it, and the last one is judged against the decision, not against a score in isolation.

Choosing the task type is usually mechanical once the target is clear:

The target is...TaskExample
One of a few categoriesClassificationWill the customer leave: yes or no?
A numberRegressionWhat will this house sell for?
A number for future periods of a time seriesTime series forecastingWeekly sales for the next 8 weeks
Not known for any row, and you want groupsClusteringWhich customers behave alike?
Not known, and you want the odd onesAnomaly detectionWhich payments look unusual?

The math

Framing turns a vague goal into something you can compute. The most useful tool is an expected value per action. Suppose the action costs cc each time you take it, and when you take it on a case that would have gone wrong, it helps with probability pp and is then worth vv. Acting on a case whose chance of going wrong is qq has expected net value:

net(q)=q⋅p⋅v−c\text{net}(q) = q \cdot p \cdot v - c

The action is worth taking when this is positive, that is when:

q>cp⋅vq > \frac{c}{p \cdot v}

The right-hand side is the break-even chance. It tells you how good a model must be before it earns anything: a model whose flagged cases are right less often than the break-even chance loses money, however high its accuracy looks. This number is a ready-made success criterion, and you can compute it before any training.

Worked example

A subscription business has 10,000 customers. About 8% (800) leave in a given quarter. A retention offer costs 20 per customer contacted. If a customer who would leave receives the offer, there is a 30% chance they stay, and a retained customer is worth 300. (All numbers are illustrative.)

Framing it.

  • Decision: who gets the offer this quarter.
  • Unit: one customer at the start of a quarter.
  • Target: "left during the quarter", yes or no. Task: classification.
  • Value of the offer per customer who would leave: 0.3×300=900.3 \times 300 = 90.

Success criterion. Break-even chance: 20/90=22.2%20 / 90 = 22.2\%. A model's flagged group must contain more than about 22% customers who would really leave, or the campaign loses money.

Doing nothing and doing everything.

  • Contact nobody: net value 0.
  • Contact all 10,000: gain 800×90=72,000800 \times 90 = 72{,}000, cost 10,000×20=200,00010{,}000 \times 20 = 200{,}000, net −128,000-128{,}000. The base rate (8%) is far below 22%, so contacting everyone loses money.

A model that helps. Suppose a model flags the 1,000 customers most likely to leave and 400 of them truly would (a hit rate of 40%, above 22.2%). Gain: 400×90=36,000400 \times 90 = 36{,}000. Cost: 1,000×20=20,0001{,}000 \times 20 = 20{,}000. Net: +16,000+16{,}000.

Notice what was agreed before training: the row, the target, the task and the number to beat. Without the criterion, "the model reaches 92% accuracy" sounds impressive, yet predicting that nobody leaves already scores 92% here.

How mlflow does it

In Pipelines, New pipeline asks for the choices you have just framed: a name, the Task (Classification, Regression, Clustering, Anomaly detection or Time series forecasting), a data source and, for supervised tasks, the Target column. Today the data-source list in that dialog shows CSV data sources only, so a file in another format has to be available as CSV first.

A project holds the data, pipelines, runs and models for one problem, so it helps to create one project per question. If you want a worked starting point, the Use cases page creates a project, dataset and pipeline from a template. The Quick train wizard on the Pipelines page is a shorter path when the framing is already clear.

Common mistakes

  • Predicting something you cannot act on. A model that predicts churn one day before the customer cancels, or a value that is only known after the decision, has no use. Check that the prediction arrives early enough for the action.
  • Using a target that leaks the answer. If the target is defined with information that is only available later (for example "cancelled, or contacted by the retention team"), the model learns the process, not the customer. Define the target from facts known at the cutoff date.
  • Mixing units. One row per customer and one row per order are different problems. Decide the unit first, then make sure every column describes that unit at that time.
  • Skipping the time window. "Will churn" has no answer until you say within how long. The window changes the target, the data you need and the value of acting.
  • Choosing the metric after seeing the scores. You will be tempted to pick whichever number looks best. Fix the success criterion first, tied to the decision.
  • Treating the task type as a free choice. If the target is a category, you are doing classification, even if you could squeeze it into a number. Start from the question, then pick the task.

Try it in mlflow

Create a pipeline and pick the task

  1. Open Pipelines and choose New pipeline.
  2. Give the pipeline a name, then pick the Task that matches your question.
  3. Pick a data source and the Target column. Check that the column is the thing you want to predict, one value per row.
Open in mlflow

Read in the docs

Check your understanding

  1. 1. A retailer asks: 'Which customers will stop buying from us in the next 90 days?' What is a sensible unit of prediction and target?
  2. 2. Which task type fits 'How many units of this product will we sell next week?'
  3. 3. Why write the success criterion before training any model?