The classical toolbox
Predicting which conversations will need a human, from account fields: what a linear model cannot see, how a tree picks its questions, and why boosting usually wins on tables.
The previous chapter’s classifier read words. This chapter’s problem reads account fields. About 18% of the broking app’s support conversations end with a human agent taking over, usually after the customer has spent several minutes going back and forth with whatever automated help was available. The team wants to predict, when a conversation opens, whether it is likely to end that way, so that those customers can be offered a human early and the rest can be served by the assistant.
At the moment a conversation opens, the system knows a good deal about the customer: how old the account is, whether a withdrawal is pending, how many orders were rejected today, whether derivatives trading is enabled, whether the market is open, how many times they contacted support in the last week, and which app version they are on. These are rows and columns, the kind of data most businesses have most of. On this kind of data, the models that win are usually not neural networks. This chapter explains why, by building the escalation predictor with a linear model and with trees and watching where each one fails.
Decide what “better” means before comparing models
We need one number to compare candidates, and it should reflect how the prediction will be used. The plan is to offer a human agent to the conversations the model ranks highest, and the agents can absorb about 10% of conversations this way. So the useful metric is precision in the top 10%: of the conversations the model ranks in its top tenth, how many really did escalate? A random ranking scores 18%, the base rate.
We split by time as before, training on six months and validating on the seventh. Then we compute the baseline that needs no model at all. Support leads already have a rule of thumb: “a pending withdrawal during market hours means trouble”. Ranking conversations by that rule (and breaking ties at random) puts 41% escalations in the top tenth. Any model must beat 41%, and must beat it by enough to justify being a model.
What a linear model can see, and what it cannot
Logistic regression on these fields is the natural first model. It learns one weight per field, adds them up, and turns the total into a probability. On the validation month it reaches 52% precision in the top tenth, a real improvement on the rule.
Its limits come from that weighted sum. Each field pushes the score up or down by an amount that does not depend on the other fields. That causes two specific problems with our data. First, a pending withdrawal matters a great deal during market hours, when customers want to move money before a trade, and much less at night, when they expect a delay. A linear model gives “withdrawal pending” one weight for both situations, so it underrates the first and overrates the second. Second, account age has a U-shaped relationship with escalation. Brand new accounts escalate often (they are confused by the KYC and funding steps), and so do very old accounts returning after years of dormancy (their bank details or nominee records are stale). Middle-aged accounts rarely do. A single weight on account age can express “older is better” or “older is worse” but not “both ends are worse”.
We can fix both by hand. Adding a column that is 1 only when a withdrawal is pending during market hours lets the linear model weight that combination separately. Replacing account age with buckets (under 30 days, 30 days to 3 years, over 3 years) lets it give each bucket its own weight. This is feature engineering, and it is where knowledge of the domain enters a classical model. With those two columns added, logistic regression rises to 56%. The cost is that someone had to know to add them, and every interaction we fail to think of stays invisible.
How a tree finds its first question
A decision tree learns the interactions instead of being told them. It works by asking yes-or-no questions about the fields, choosing at each step the question that best separates escalations from the rest. “Best” needs a number, and a common one is Gini impurity: for a group where a fraction p escalates, impurity is 1 − p² − (1 − p)². It is zero when the group is all one kind and highest when it is an even mix.
Take a sample of 1,000 conversations, of which 180 escalated. Impurity is 1 − 0.18² − 0.82² = 0.295. The tree considers splitting on “withdrawal pending”. Of the 200 conversations with a pending withdrawal, 110 escalated (55%), impurity 0.495. Of the 800 without, 70 escalated (8.75%), impurity 0.160. Weighting each side by its size, 0.2 × 0.495 + 0.8 × 0.160 = 0.227. The split lowers impurity by 0.068.
It then considers “market open”. Of the 600 conversations during market hours, 140 escalated (23%), impurity 0.358. Of the 400 outside, 40 escalated (10%), impurity 0.180. The weighted total is 0.6 × 0.358 + 0.4 × 0.180 = 0.287, a drop of only 0.009. The tree asks about withdrawals first. Then, within the “withdrawal pending” branch, it repeats the search, and it may well find that “market open” is now the best question there, which is the interaction we had to hand-code for the linear model. The tree discovered it because it asks each question only of the conversations that reached that branch.
Left alone, a tree keeps splitting until each leaf holds a handful of conversations that all went the same way. A leaf that says “accounts on app version 5.1.3, opened in March, with exactly two rejected orders, escalate” is describing three customers, not a pattern. A single deep tree on our data reaches 70% top-tenth precision on training and 44% on validation, which is barely above the rule. Limiting depth helps, but a shallow tree misses detail. The standard answer is to use many trees.
A single tree is trained on six months of conversations. A second tree is trained on the same six months with 5% of rows dropped at random. Will the two trees ask the same first question? Will they agree on the last few levels?
Show the worked answer
The first question will almost certainly be the same. The withdrawal split beats its rivals by a wide margin, and dropping 5% of rows does not change that.
The deep levels will differ a lot. Down there each branch holds a few dozen conversations, the best and second-best splits are separated by tiny amounts, and removing a few rows flips which one wins. Each different choice then changes everything beneath it. This instability is the overfitting in another form: the deep structure reflects which rows happened to be present. It is also the reason averaging many trees works, since the random parts disagree and cancel while the shared structure agrees and remains.
Two ways to turn many trees into one prediction
A random forest trains a few hundred deep trees, each on a random resample of the rows and considering a random subset of fields at each split, and averages their predictions. Each tree overfits in its own way, the errors are partly independent, and the average is much steadier than any member. Forests need little tuning and are hard to break, which makes them a good second model to try. On our data a forest reaches 59%.
Gradient boosting builds trees in sequence instead. The first tree is small, often only three to six levels deep, and makes rough predictions. The second tree is trained to predict the errors of the first: where the first said 0.30 for a conversation that did escalate, the second tree learns to push that one up. The third corrects what the first two still get wrong, and so on, for hundreds of rounds, each tree’s contribution shrunk by a learning rate so that no single tree dominates. Libraries such as XGBoost and LightGBM implement this efficiently. On our data, after tuning depth, learning rate and the number of rounds against the validation month, boosting reaches 61%.
| Model | Top-10% precision | What it buys | What it costs |
|---|---|---|---|
| Support lead’s rule | 41% | no training, fully explainable | one interaction, chosen by hand |
| Logistic regression | 52%, 56% with two crafted columns | fast, calibrated, weights are readable | interactions and curves must be hand-built |
| Single deep tree | 44% | finds interactions | memorises small branches, unstable |
| Random forest | 59% | stable, little tuning | hundreds of trees to serve, scores less calibrated |
| Gradient boosting | 61% | usually the most accurate on tables | more knobs, easier to overfit, needs early stopping |
The team shipped the boosted model, and the decision reads: “We use gradient boosting because it beats the rule by 20 points and logistic regression by 5, the extra serving cost is a few milliseconds per conversation, and we accept that its scores need calibrating before we use them as probabilities.” If the gap over logistic regression had been one point, the readable weights and simpler monitoring of the linear model would have won.
The encoding that leaked the answer
One feature deserves its own walk-through. The team noticed that some customers escalate almost every time and others never do, and wanted the model to know which kind it was talking to. A customer id has millions of possible values, far too many for a column each, so they used target encoding: replace each customer id with that customer’s historical escalation rate.
The first version computed that rate over the whole dataset, then split by time. Top-tenth precision jumped from 61% to 78%. Here is why that number was false. For a customer with two conversations in the training period, one of which escalated, the encoded rate was 0.5, and that rate was computed using the very label the model was trying to predict. The model was partly reading its own answer. Worse, for customers whose conversations fell in the validation month, the rate included those validation conversations too.
In production the encoded value can only use conversations that finished before the current one. The team rebuilt the feature so that, for each conversation, the rate was computed only from that customer’s earlier conversations, and new customers got the overall average. Precision settled at 64%: a real three-point gain over 61%, not the seventeen it had seemed. The fix cost a more complicated feature pipeline that has to compute the rate as of each timestamp, both in training and in serving, and the two implementations must stay identical or the model will see different numbers in production than it learned from. That last requirement, keeping training and serving features consistent, is a large part of why companies build feature stores.
Text is where linear models still win
It would be easy to conclude that boosting should replace logistic regression everywhere. The intent classifier from the previous chapter is a counterexample. There, each message becomes a vector with one column per word in a vocabulary of about 50,000, nearly all zeros. Trees split on one column at a time, and on such sparse data most splits isolate a handful of messages. A linear model, by contrast, can give a small weight to each of thousands of relevant words and add them up, which suits text well. Logistic regression on word counts weighted by how rare each word is across messages (TF-IDF) remains a strong, fast text baseline, and boosting on the same columns usually does not beat it by enough to matter.
The same sparse vectors show a weakness that will matter later. Compare two messages by the words they share and “withdrawal still pending” has nothing in common with “money not credited to my bank”, even though an agent would file both in the same queue. Methods that work by distance, such as k-nearest neighbours, which labels a message by the labels of its closest training messages, suffer most. In 50,000 dimensions where almost every coordinate is zero, nearly every pair of short messages is about equally far apart, so “nearest” carries little meaning. The fix is not a better classifier but a better representation, one in which messages with similar meaning sit close together. Building that representation is what the next chapter’s networks do.
Finding the queue nobody has labelled yet
Everything so far needed labels. One problem the triage desk had did not come with any. The “other” queue had grown from 4% of messages to 9% over three months, and nobody knew why. Reading a few hundred by hand suggested several different things were going on, but not how many or how large each was.
Clustering finds groups without labels. k-means, the most common method, takes a number of groups k, places k centre points, assigns every message to its nearest centre, moves each centre to the average of its messages, and repeats until assignments stop changing. Run on the “other” messages, represented as TF-IDF vectors, with k = 8, it produced one large cluster that was plainly about a newly launched feature for pledging shares as margin. Word vectors are a weak way to measure meaning, as a later section explains, but this topic had distinctive vocabulary (“pledge”, “unpledge”, “collateral”) and that was enough. The feature had no queue and no help article. That finding became a new queue, a new article and, a month later, a new label for the intent classifier.
Two cautions came with it. k-means always returns k groups, whether or not the data has that many natural groups, so the clusters are a starting point for a person to read and name, not a result. And with numeric fields rather than words, it is sensitive to scale: cluster accounts on balance in rupees and number of logins, and the balance column, whose values run into lakhs, decides the clusters on its own unless every field is first rescaled to a comparable range. The output of clustering is a hypothesis, checked by reading examples from each group.
Two things the model cannot tell you
The boosted model reports feature importances, and the top one is “rejected orders today”. It is tempting to read this as a cause and conclude that reducing order rejections would reduce escalations. The importance says only that this field was useful for predicting escalation in this data. Rejections and escalations could both be driven by a third thing, such as volatile markets, and fixing rejections might change little. Questions about cause need experiments, not importances.
The second is that the model describes the period it was trained on. App version was a strong feature, because version 5.2 shipped with a bug in the withdrawal screen and its users escalated heavily. When 5.2.1 fixed the bug, the model kept raising scores for anyone on a 5.2 build, and kept offering human agents to customers who no longer needed them. Any field that reflects a temporary condition will eventually mislead. The defence is to monitor precision on recent conversations every week and retrain on a rolling window.
When to skip this toolbox
Classical models need structured inputs. When the signal lives in free text, images or audio, hand-built columns cannot capture it, and the next chapter’s methods are the way in. When there are only a few hundred labelled rows, a boosted model will overfit and a simple rule reviewed by a domain expert may be more reliable. And when the decision is rare and high-stakes, a model may be the wrong frame entirely: if the business requires a human to review every account freeze, a predictor only changes the order of the queue.
For the large middle ground of tabular business problems with tens of thousands of rows or more, the order of work holds up well: compute the rule-of-thumb baseline, fit logistic regression with a few crafted columns, try a forest, try boosting, and ship the simplest one whose margin over the next simpler one pays for its extra complexity.
Deep learning fundamentals picks up the paraphrase problem. The team wants a representation of support messages in which “funds not credited” and “withdrawal stuck” land near each other, and that means learning features rather than writing them.
Free PDF. The standard text for exactly this stage — read it with the labs, skip nothing in chapters 2–8.
Reference docs that double as a course — every classical method with its assumptions and pitfalls.