Skip to content

Volume ITechnology

12.1.2 — The Kinds of Problems ML Solves ​

Cartwise's delivery team brings you a complaint: customers are angry about late parcels. They want "some AI" to help. Before anyone writes a line of code, you have to decide what exactly the model should output, because that one decision changes everything that follows. Here are four different models you could build from exactly the same data:

  1. "Will this parcel be late, yes or no?" The model outputs one of two labels.
  2. "How many days will this parcel take?" The model outputs a number, such as 3.4.
  3. "Which of these five couriers should we hand this parcel to?" The model outputs an ordering of the five, best first.
  4. "Write the customer an apology message that explains the delay." The model outputs a paragraph of new text.

All four are machine learning. All four can be trained on Cartwise's history of past deliveries. But they need different models, different training data, different ways of measuring success, and they fail in different ways. The first skill of an AI engineer is recognising which of these jobs the business actually needs, and this page is the catalogue of jobs.

1. What the model outputs: the task types ​

Every machine learning task can be described by one sentence: given this input, produce that kind of output. The input is usually called x and the output y, which is the same naming you used in school algebra for "the thing you put in" and "the thing you get out". What changes from task to task is the shape of y.

Binary classificationan orderfraudorgenuineMulti-classa support emailrefunddeliveryaccountpaymentexactly oneMulti-labela product photoshoeredleatherany number of tagsRegressiona parcel3.4 daysany number on a scaleRankinga search + 500 items1. rain jacket2. windbreaker3. umbrella …an order, best firstClusteringall customersgroups, with no names givenGeneration"write an apology""Hi Priya, we're sorry your parcel isrunning two days late because…"new content
Seven kinds of output. The blue box on the left is the input x, and everything to the right of the arrow is the shape of the output y. Picking the row is the first design decision on any ML project.

We will now go through each row of that figure and say, for each one, what it is, what it looks like at Cartwise, and the trap that catches people.

Classification: pick a label ​

Classification means the output is a label from a fixed list that you decide in advance. There are three variants, and the difference between them matters more than it sounds.

Binary classification has exactly two labels: fraud or genuine, spam or not spam, will churn or will stay. It is by far the most common task in business ML. In practice, the model almost never outputs the label directly. It outputs a probability, such as "0.83 chance of fraud", and your code then compares that probability to a threshold you choose to turn it into a decision. If the threshold is 0.5, an order at 0.83 is blocked. If you raise the threshold to 0.9, the same order passes. That threshold is a business decision, not a modelling one, because it trades off blocking real customers against letting fraud through. Chapter 12.3.2 shows how to pick it from the actual cost of each kind of mistake.

Multi-class classification has more than two labels, and each input gets exactly one. Cartwise's support inbox receives 40,000 emails a week, and routing each one to the right team (refunds, delivery, account, payment) is a multi-class problem. The model outputs one probability per class, and the probabilities add up to 1, so an email might come out as 0.71 refund, 0.20 delivery, 0.06 payment and 0.03 account. Chapter 12.2.6 explains the small piece of maths, called softmax, that forces those numbers to add up to 1.

Multi-label classification also has a fixed list of labels, but each input can have any number of them, including none. A product photo can be "shoe" and "red" and "leather" all at once. The model gives one independent yes-or-no probability per label, and these do not need to add up to 1. The trap here is a common bug: people build a multi-class model when the problem is really multi-label, and the model is then forced to pick "red" or "shoe", which makes no sense.

Regression: predict a number ​

Regression means the output is a number on a continuous scale: delivery days, tomorrow's sales, the price a used phone will sell for. The word has a strange origin. In the 1880s the scientist Francis Galton measured the heights of parents and their adult children and noticed that very tall parents tended to have children who were tall but slightly less tall than them, and very short parents had children slightly less short. The children's heights "regressed towards the mean", meaning they drifted back towards the average. The mathematical method he used to draw the line through that data became known as regression, and the name stayed attached to the method even when it was used for things that have nothing to do with drifting back to an average.

The trap with regression is that a single number hides how unsure the model is. "3.4 days" might mean "almost certainly between 3 and 4 days" or "anywhere from 1 to 10 days". When the decision depends on the risk, like promising a delivery date to a customer, you often want the model to also predict a range. Chapter 12.3.1 builds regression from the ground up.

Ranking and recommendation: put things in order ​

Ranking means the output is an ordering of a set of items. When a Cartwise customer searches for "rain jacket", there might be 500 products that match. The customer will look at maybe the first ten. So the real job is not deciding which items match. It is deciding which ten go at the top, and in what order.

You might think ranking is just regression in disguise: predict a relevance score for each item and sort by it. That is often how it is built. But the way you measure success is different, and that difference changes how you train the model. Getting the top three right matters enormously. Getting items 400 to 410 in the right order does not matter at all. A ranking model is judged on the top of the list, and Chapter 12.9.5 teaches the measures that work that way.

Recommendation is ranking where nobody typed a query. "Customers who bought this also bought" and the products on Cartwise's home page are recommendations: the model ranks the whole catalogue for one particular person. Chapter 12.12.6 shows how it is done at the scale of millions of items without scoring every item for every person.

Clustering and anomaly detection: find structure with no answers given ​

In every task so far, somebody knows what the right answer looks like. Clustering is different. You give the model a pile of examples and no labels at all, and ask it to find groups of similar ones. Cartwise's marketing team might cluster its customers by what they buy and how often, and discover that there is a group of people who buy only during sales, a group who buy expensive electronics twice a year, and a group who buy groceries every week. Nobody told the model those groups existed. The catch is that the model also does not name them. It returns "group 1, group 2, group 3", and a human has to look at each group and work out what it means, which is sometimes nothing at all.

Anomaly detection asks "which of these examples is unlike the others?" It is how you catch a new kind of fraud that has never been labelled, or a warehouse sensor that is about to fail. Both clustering and anomaly detection are covered in Chapter 12.3.6.

Generation: produce something new ​

Generation means the output is a new piece of content: a paragraph, an image, an audio clip, a block of code. The apology message, a product description written from a seller's bullet points, a summary of a long support thread. This is where LLMs live.

Generation has a property none of the other tasks have, and it is the source of most of the engineering difficulty in Chapters 12.8 to 12.10: there is usually no single right answer. A fraud label is right or wrong. An apology message can be good in a thousand different wordings and bad in a thousand others, and two careful people might disagree about which version is better. That makes generation hard to measure, and Chapter 12.8.6 is about how to measure it anyway.

One problem, several framings ​

Go back to the delivery team. Here is what the training data looks like for three of the framings, using the same five past parcels. Only the y column changes:

python
# five past parcels: distance in km, weight in kg, was it a holiday week (1 = yes)
X = [[ 12,  1.0, 0],
     [450,  3.5, 1],
     [ 30,  0.4, 0],
     [900, 12.0, 1],
     [ 60,  2.2, 0]]

y_late    = [0, 1, 0, 1, 0]                       # (1) classification: late or not
y_days    = [1.0, 4.5, 1.5, 6.0, 2.0]             # (2) regression: actual days taken
y_courier = ["FastShip", "SlowPost", "FastShip",  # (3) multi-class: which courier did best
             "BulkCargo", "FastShip"]

Line (1) gives one 0 or 1 per parcel, so a model trained on it learns to answer "late or not". Line (2) gives the real number of days, so a model trained on it learns to predict a duration. Line (3) gives one courier name per parcel, so a model trained on it learns to pick a courier.

The inputs in X are identical in all three cases. What you choose to put in y is what decides which problem you are solving. And notice that the choice is not neutral. The regression framing in (2) holds strictly more information than the classification framing in (1), because if you know a parcel took 4.5 days you also know it was late, but not the other way round. When you can collect the richer label, it is usually worth doing so, because you can always turn a number into a yes-or-no later, but you can never turn a yes-or-no back into a number.

2. Where the right answers come from: the learning setups ​

The second thing that defines an ML problem is where the right answers come from during training, and how much of them you have. There are four main setups.

① SUPERVISEDevery example comes with its answerorder #1 → fraudorder #2 → genuineanswers from disputes, human reviewers② UNSUPERVISEDno answers at all; find the structuregroups, outliers③ SELF-SUPERVISEDthe answer is a hidden piece of the data itself"Your parcel will arrive on ___"answer: "Thursday"free labels at enormous scale: how LLMs learn④ REINFORCEMENTact, then receive a reward or penaltymodel actsreward: +1 / −1learn which actions earn reward
The four ways a model can get the right answers it learns from. The colour of each panel matches the order they appear below.

① Supervised learning: examples with answers ​

In supervised learning, every training example comes with the right answer attached, and that answer is called the label. Cartwise's fraud model is supervised: every past order is labelled fraud or genuine. The word "supervised" comes from the image of a teacher checking each answer: the label plays the role of the teacher, telling the model whether each guess was right.

Supervised learning is the workhorse of business ML because it is the most reliable. Its one big weakness is the labels themselves. Somebody or something has to produce them, and they are often slow, expensive or wrong. Cartwise's fraud labels arrive only when a dispute comes back, which takes up to sixty days, so the most recent two months of orders have no reliable label yet. Medical image labels need a doctor's time. Chapter 12.4.1 is about getting good labels, because in practice it decides the quality of the model more than the choice of algorithm does.

② Unsupervised learning: no answers, find the structure ​

In unsupervised learning there are no labels at all. The model looks for structure in the inputs alone: groups of similar examples, unusual examples, or a simpler way to describe the data. Clustering and anomaly detection from section 1 are the main uses. It is cheaper because no labels are needed, but it is harder to judge, because without a right answer there is no simple way to say whether the result is good.

③ Self-supervised learning: the data labels itself ​

Self-supervised learning is the idea that made LLMs possible, and it is a clever trick. You take unlabelled data, hide part of it, and ask the model to predict the hidden part. The hidden part is the label, so you get labels for free, without any human involved.

Take the sentence "Your parcel will arrive on Thursday." Hide the last word, and you have a training example: the input is "Your parcel will arrive on" and the label is "Thursday". Hide a different word and you have another example. Every sentence ever written becomes dozens of training examples, which is how LLMs are trained on trillions of words when no human could ever label that much. It is called self-supervised because the data supervises itself. Image models use the same trick by hiding patches of a photo and asking the model to fill them in.

The reason this matters so much is a property you will meet again and again: a model that has been trained to fill in blanks across a huge amount of data has learned general knowledge that can be reused for specific tasks with very few labels. Cartwise does not have enough labelled support emails to teach a model English from nothing. But it can take a model that already learned English through self-supervision and teach it Cartwise's four email categories with a few thousand examples. Reusing a model trained on one job for a different job is called transfer learning, and Chapter 12.5.7 and Chapter 12.11 both rely on it.

④ Reinforcement learning: act and get rewarded ​

In reinforcement learning, the model is not shown right answers at all. It takes actions in some environment, and after a while it receives a reward: a number that says how well things went. It has to work out for itself which of its actions led to the reward. A program learning to play a video game gets a reward when the score goes up. The checkers program in 12.1.1 was an early version of the same idea: it learned from which games it won.

The name comes from the psychology of animal learning, where behaviour that is followed by a reward is "reinforced", meaning it becomes more likely to happen again. The hard part is called the credit assignment problem: if you win a chess game after forty moves, which of the forty moves deserves the credit?

You will not build reinforcement learning systems often as an AI engineer, but you need to understand it, because it is one of the steps that turns a raw LLM into a helpful assistant. People rate the model's answers, those ratings become rewards, and the model is trained to produce answers that earn higher ratings. That process, reinforcement learning from human feedback, is explained in Chapter 12.7.9.

The in-between: a few labels and a lot of unlabelled data ​

Real projects rarely fit one box neatly. The common situation at Cartwise is having two million unlabelled support emails and only three thousand labelled ones. Using both together, the small labelled set to learn the task and the big unlabelled set to learn what emails look like, is called semi-supervised learning. In practice today, the most common way to do it is the transfer learning just described: start from a model that self-supervised on a huge amount of text, and teach it the task with your small labelled set.

3. Putting both questions together ​

Any ML problem can be pinned down by answering the two questions of this page: what shape is the output, and where do the right answers come from? Here are Cartwise's four running problems placed on both axes:

Cartwise problemOutput shapeAnswers come from
Fraud at checkoutbinary classificationsupervised (disputes)
Product searchrankingsupervised (clicks, purchases)
"Ask Cartwise" assistantgenerationself-supervised, then tuned
Refund agentgeneration + actionsself-supervised model, rules from you

The first two rows are classical ML problems: you will train your own models for them in Chapters 12.3 and 12.6. The last two rows are AI engineering problems: you will not train the underlying model at all, because somebody else already did the self-supervised training on trillions of words. Your work there is to use that model well, which is what Chapters 12.8 to 12.10 are about.

Recall

  • Every ML task is "given input x, produce output y", and the shape of y defines the task: classification (binary, multi-class, multi-label), regression, ranking and recommendation, clustering, anomaly detection, and generation.
  • A classifier usually outputs a probability, and a threshold you choose turns it into a decision. Multi-class probabilities add to 1; multi-label probabilities are independent.
  • The same inputs can be framed as different tasks just by changing the label column. A richer label (a number of days) can always be turned into a poorer one (late or not), never the reverse.
  • The learning setups: supervised learning uses a label on every example, unsupervised learning uses none, self-supervised learning hides part of the data and predicts it (how LLMs learn), and reinforcement learning learns from a reward after acting.
  • Transfer learning reuses a model trained on a big general job for a small specific one, which is why a few thousand labels can be enough.

Self-test: A product photo can be both "red" and "shoe". Which classification variant is that, and what goes wrong if you build the other one? Why does "how many days" carry more information than "late or not"? Where do the labels come from when an LLM is trained on raw text?

Next: 12.1.3 From Business Problem to ML Problem — knowing the task types is not enough; the harder skill is turning a vague request like "use AI to reduce late deliveries" into a problem you can build, measure, and beat with a simple baseline first.