Regression, Classification or Ranking: Picking the Right Task Type
Choose between predicting a number, a category or an order by working backward from the decision your model has to support.
Key takeaways
- Regression predicts a number, classification predicts a category or its probability, and ranking predicts an order within a group.
- Start from the action taken on the output: set a quantity, make a yes-or-no call, or work down a list.
- Turning a number into classes throws away information, so do it only when the decision truly hinges on a fixed cutoff.
- A good classifier probability can serve as a ranking score, while a pure ranking score usually is not a probability.
- Match the loss function and the evaluation metric to the task you chose.
Pick the task type from the decision the output will drive. Use regression when someone needs a quantity, such as minutes until delivery. Use classification when someone needs to know which category applies, such as fraud or legitimate. Use ranking when someone needs a sorted list and will act from the top, such as search results or a call queue.
The same raw data can usually support all three. The choice changes what the model is penalized for, which metrics make sense and how useful the output is in practice.
The three tasks side by side
| Question | Regression | Classification | Ranking |
|---|---|---|---|
| Target | A number | One of K categories | Relative order |
| Typical output | ŷ in the target's units | Probability per class | A score per item |
| Common loss | Squared or absolute error | Cross-entropy (log loss) | Pointwise, pairwise or listwise |
| Common metrics | MAE, RMSE | Precision, recall, AUC, log loss | NDCG, mean average precision |
| A mistake means | Being far off | Picking the wrong category | Putting a worse item above a better one |
A loss function is the quantity training tries to make small. A metric is what you report. They need not be identical, but they should reward the same behavior. The idea is developed in loss functions as a definition of success.
Work backward from the decision
Ask what happens in the minute after the prediction arrives. Say you run a subscription business and worry about cancellations. Three framings are all defensible.
- Regression: predict how many days remain before a customer cancels. This suits planning, but customers who have not canceled yet have no known value, which calls for survival analysis.
- Classification: predict whether the customer cancels in the next 30 days. This suits an automatic action, such as sending an offer when the probability passes a threshold.
- Ranking: order customers by urgency. This suits a team that can phone exactly 50 people a day and simply works from the top.
None is correct in the abstract. The third matches a fixed capacity, and the second matches a per-customer cost and benefit.
What each loss rewards
Within a task type, the loss still shapes the answer. In regression, squared error pushes the model toward the conditional mean, the average outcome for inputs like these. Absolute error pushes it toward the median. When the outcome is skewed, as with spending or waiting times, the two can differ a great deal.
Suppose that for one kind of order, nine deliveries in ten take 30 minutes and one takes 130. The mean is 40 minutes and the median is 30. A squared-error model should quote about 40, while an absolute-error model should quote about 30. Neither is wrong. They answer different questions, and a customer promised "30 minutes" experiences the tail differently from a planner adding up total driver time.
In classification, log loss rewards honest probabilities, because a confident wrong answer is punished heavily. Accuracy cares only about which side of the threshold a case falls on, so it cannot distinguish a prediction of 0.51 from one of 0.99. Accuracy is also flat almost everywhere as weights change, which is why training uses a smooth stand-in such as log loss and reports accuracy afterward.
Should you turn a number into classes?
It is tempting to convert a numeric target into "high" and "low." This discards information. If the cutoff for a late delivery is 40 minutes, then 41 and 120 minutes receive the same label, while 39 and 41 receive opposite ones even though they barely differ.
A regression model keeps the magnitude, and you can apply any cutoff afterward. That is handy when the threshold may change.
Classification still wins in some situations. The recorded numbers may be unreliable while the category is trustworthy. The outcome may have a long, wild tail that dominates squared error. Or the only thing that matters may be the probability of crossing a line, which a classifier estimates directly. A third option is quantile regression, which predicts points of the distribution, such as the delivery time exceeded only one time in ten.
Classification has variants
Binary classification has two classes. Multiclass picks exactly one of several. Multilabel allows any number to be true at once, as with topic tags on an article. Ordinal problems have ordered categories, such as ratings from 1 to 5, where predicting 4 for a true 5 is a smaller error than predicting 1.
For decisions, prefer probabilities to hard labels. A probability lets you move the threshold when costs change. Suppose a missed fraud costs 20 times as much as a false alarm, and correct decisions cost nothing. With well-calibrated probabilities, flagging pays off when p × 20 > (1 − p) × 1, which means p > 1/21, or about 0.048. A default cutoff of 0.5 would be badly wrong here. See choosing thresholds from costs.
Calibrated means that among cases given probability 0.2, about 20 percent turn out positive. Many models need checking and adjustment before that holds.
How ranking differs
A ranking model only has to get the order right within a group: the results for one query, or the candidates for one user. The absolute score is irrelevant, since adding 100 to every score changes nothing.
There are three broad training styles. Pointwise methods predict each item's relevance on its own, which is ordinary regression or classification. Pairwise methods compare two items at a time. Listwise methods score the whole list. Learning to rank compares them.
A common pairwise loss is log(1 + exp(−(sᵢ − sⱼ))), using the natural log, where item i should rank above item j. With scores 2 and 1 the loss is about 0.31. With the order reversed, scores 1 and 2, it is about 1.31. The penalty grows as the model gets the pair more wrong.
Measuring a ranking
Ranking metrics care most about the top of the list. NDCG (normalized discounted cumulative gain) divides each item's relevance by log₂(position + 1), adds these up, and divides by the best possible total.
Say three results have relevance 3, 0 and 2 in the order shown. Using relevance itself as the gain:
DCG = 3/log₂2 + 0/log₂3 + 2/log₂4 = 3 + 0 + 1 = 4.00
ideal = 3/log₂2 + 2/log₂3 + 0/log₂4 ≈ 3 + 1.26 + 0 = 4.26
NDCG ≈ 4.00 / 4.26 ≈ 0.94 Some libraries use 2^relevance − 1 as the gain instead, which weights highly relevant items more. Check which one your tool computes. Other ranking metrics answer slightly different questions.
Labels differ by task too
The framing also decides what data you must collect. Regression needs a recorded quantity. Classification needs a category and a clear rule for assigning it, including a time window such as "canceled within 30 days."
Ranking needs judgments of relative value within a group. These may come from raters who grade results, or from behavior such as clicks and purchases. Behavioral signals are plentiful but biased: items shown near the top get clicked partly because they were near the top. Treating every unclicked item as irrelevant teaches the model to copy the old system. Logging what was actually shown, and where, makes later correction possible.
Check that your labels exist in sufficient numbers for the framing you like. A rare event might give you millions of rows and only a few hundred positives, and the positives limit what any of the three framings can learn.
You can often combine them
A binary classifier's probability can be used to sort items, and this is a perfectly good first ranking system. If the classifier separates positives from negatives well, its ordering will be useful. The area under the ROC curve has exactly a ranking meaning: it is the chance that a randomly chosen positive scores higher than a randomly chosen negative, counting ties as half.
Many systems also multiply predictions. Expected revenue from showing an item might be the probability of purchase (a classifier) times the amount spent given purchase (a regression). Ranking by that product requires both parts to be on a meaningful scale, so calibration matters.
Warning signs of the wrong choice
Watch for these symptoms during early experiments.
- You report accuracy, but users only ever look at the first five items.
- You rank items, but downstream code needs a probability to compute costs.
- Your regression is dominated by a few enormous values, while the decision treats all large values alike.
- You treat ordered grades as unrelated classes and see wildly distant errors.
- Your classes were created by cutting a number at an arbitrary point that stakeholders keep wanting to move.
Decide, then test the framing
Write one sentence of the form "For each ___, predict ___, so that ___ can ___." If you cannot finish it, return to turning the question into a learning problem.
Then try two framings cheaply with simple models and judge both by the same downstream measure, such as the number of cancellations caught among the 50 calls made. That comparison tells you more than any argument about which task type is more natural, and it often takes less than a day of work.