Topic 6 of 6 · 4 min read
When classic ML beats an LLM
Goal: Decide between a classic model and an LLM call for a given task using cost, latency, accuracy and explainability figures.
For structured, high-volume prediction with labelled history, a classic model is usually cheaper, faster, more consistent and easier to explain than an LLM call; use the LLM when the input is free-form language or you have no labels. Choose by measuring, not by fashion.
Check yourself · 1 of 3
Which task is the best fit for a gradient-boosted tree model rather than an LLM?
Why it matters
An LLM can classify almost anything after a prompt, which makes it tempting for every task. But each call costs money and takes hundreds of milliseconds to seconds, and the answer can vary between runs. A gradient-boosted model on a table of 40 columns scores a row in well under a millisecond on a CPU, costs close to nothing per prediction, and returns the same output for the same input. At a million predictions a day, the difference decides whether a feature is affordable.
How to decide
Compare on your own task, with the same test set:
- Input type. Rows and columns (price, age, counts, flags): classic ML. Free text, images or documents with no labels: LLM, or a hybrid.
- Labelled data. Thousands of labelled rows point to classic ML. Zero labels point to an LLM prompt, which can also generate labels for a classic model to learn from later.
- Volume and latency. High volume or a hard latency budget favours classic ML.
- Explainability and audit. SHAP values and coefficients can be shown to a regulator. An LLM's stated reasoning is generated text, not a faithful trace of why it answered.
- Accuracy. Measure both on the same held-out set. Do not assume either wins.
A common good design is a hybrid: use an LLM to turn messy text into a few structured fields, then feed those into a tabular model.
Before and after
Before: "Send each transaction as text to an LLM and ask whether it is fraud." After: build features from the transaction table (amount, merchant category, time since last purchase, count of transactions in the last hour), train a boosted model on past labelled fraud, and keep the LLM for the free-text dispute notes.
Illustrative figures (assumed prices, check your own): an LLM call at 0.2 cents with 800 ms latency, against a self-hosted tree model at roughly 0.0001 cents and 1 ms. At 2 million predictions a month that is 4,000 dollars against about 2 dollars.
import time
t0 = time.perf_counter()
proba = model.predict_proba(X_batch)[:, 1]
print("ms per row:", 1000 * (time.perf_counter() - t0) / len(X_batch))
What goes wrong
- Using an LLM because it needs no training, then paying per call forever.
- Comparing on different data, or tuning the prompt on the test set.
- Ignoring run-to-run variation in LLM outputs when a decision must be repeatable.
- Forcing classic ML onto text by counting words when the meaning matters.
Examples
Comparison table
| Boosted trees | LLM prompt | |
|---|---|---|
| Accuracy (F1, same 5,000 test rows) | 0.91 | 0.84 |
| Latency per row | 1 ms | 800 ms |
| Cost per 1,000 rows | about 0.001 USD | about 2 USD |
| Same input, same output | yes | not guaranteed |
| Needs labelled data | yes | no |
These figures are an example of how to lay out the comparison, not benchmarks.
Ticket triage
Support tickets arrive as free text with no labels. Start with an LLM to tag 2,000 of them by topic. Check a sample by hand, then train a small classifier on those tags with the plain-text features. Run the cheap classifier on the full stream and send only low-confidence tickets back to the LLM.
Key points
- Classic models win on structured, high-volume tasks with labelled history: cheaper per prediction, lower latency, repeatable outputs.
- LLMs win on free-form text and tasks with no labels, where a prompt replaces training data.
- Compare both on the same held-out set and report accuracy, cost per 1,000 predictions, latency and whether you can explain a decision.
- An LLM's explanation of its answer is generated text, while SHAP values and coefficients are computed from the model.
- A hybrid, with an LLM extracting fields and a tabular model deciding, is often best.
Common mistakes
- Choosing an LLM for a table of numbers because it needs no training.
- Comparing the two on different test data or after tuning the prompt on the test set.
- Counting only the API price and leaving out engineering time, monitoring and retraining.
- Treating an LLM's written reasons as an audit trail.
Check yourself · 2 of 3
A regulator asks why a specific loan was declined. Which approach supports a computed, per-decision explanation?
Check yourself · 3 of 3
You have no labelled data for a new text classification task and need results this week. What is a sensible first step?
Practice items, not counted towards your mastery.
Start here
- scikit-learn: ensembles (gradient boosting, random forests) (opens in a new tab)DocsFree
Reference for random forests and histogram gradient boosting, with the parameters that matter.
- XGBoost documentation (opens in a new tab)DocsFree
Official docs for the most used boosted-tree library, including parameter tuning notes.
- Why do tree-based models still outperform deep learning on tabular data? (opens in a new tab)PaperFree
The benchmark paper behind the claim that trees lead on medium-sized tabular data.