A product manager forwards a request: "We have three years of refund requests. Can we train a model to decide which ones go to manual review?" A sprint later, the model scores almost 99% on held-out requests and the demo goes well. Then someone asks the support lead how requests were routed until now. The answer is one sentence in the refund policy: a refund larger than what the customer paid goes to a human. The team spent a sprint teaching a model to imitate that sentence, and the cases it gets wrong are the borderline ones that support hears about.
The common misconception
When a problem comes with data, many developers assume a trained model will beat any rule a person could write. The belief has good reasons behind it:
On problems nobody can describe in code, such as recognizing objects in photos or ranking search results, machine learning really does win, and those are the success stories everyone hears.
Rules have a bad reputation. Anyone who has inherited a sprawling if/else chain knows how it rots, and Google's own Rules of Machine Learning calls a complex heuristic unmaintainable.
"Data-driven" sounds more rigorous than "a rule someone wrote", and "we use ML" sounds better on a roadmap.
It's a half-truth. beats rules when the logic is unknown or too complex to maintain, and you have good data to learn it from. When the logic is known, or a simple rule gets most of the way, a model adds cost and error for little gain.
What actually happens
A model doesn't discover your business logic. Training fits a function to examples, and the result is only as exact as those examples allow. That one fact explains when rules win.
A model approximates; code states
If a rule produced your labels, the best a model can do is copy that rule, and it copies it approximately. Here's the refund story with synthetic data: 5,000 requests labeled by the policy, a decision tree trained on them, and the policy written as code.
Python
import numpy as npfrom sklearn.model_selection import train_test_splitfrom sklearn.tree import DecisionTreeClassifierrng = np.random.default_rng(0)paid = rng.uniform(10, 200, 5000).round(2) # what the customer paidrefund = rng.uniform(0, 250, 5000).round(2) # what they ask backX = np.column_stack([paid, refund])y = (refund > paid).astype(int) # labels came from the review policyX_tr, X_te, y_tr, y_te = train_test_split(X, y, random_state=0)model = DecisionTreeClassifier(random_state=0).fit(X_tr, y_tr)print(f"accuracy {model.score(X_te, y_te):.3f}") # accuracy 0.988print(f"leaves {model.get_n_leaves()}") # leaves 60print(model.predict([[120, 121], [400, 300]])) # [0 1]: both wrong
Python
from decimal import Decimaldef needs_review(paid: Decimal, refund: Decimal) -> bool: """Refund policy: a refund larger than the payment goes to a human.""" return refund > paidassert needs_review(Decimal("120.00"), Decimal("121.00"))assert not needs_review(Decimal("400.00"), Decimal("300.00"))assert not needs_review(Decimal("50.00"), Decimal("50.00"))print("policy cases pass")
The tree prints a test accuracy of 0.988 and still gets both sample requests wrong. A $121 refund on a $120 order isn't flagged: close to the policy's line, the tree's boundary is a staircase that sits a little off. A $300 refund on a $400 order is flagged: the training data never had payments above $200, and scikit-learn's user guide warns that tree predictions are piecewise constant approximations, not good at extrapolation. To approximate one comparison, the tree grew 60 leaves. The function is exact everywhere, and its boundary cases are unit tests.
Every model comes with running costs
Google's problem-framing course is blunt about this: ML can cost significantly more compute and time to implement, and it often needs dedicated long-term maintenance. It also needs data that is abundant, consistently collected, correctly labeled, representative of the real world and available at prediction time in the right format. A rule needs a code review and a test.
Change is cheaper too. When the policy moves, the rule changes in one line. A model keeps applying the old policy until you have enough examples labeled under the new one to retrain it.
The heuristic is your benchmark
Google's Rules of Machine Learning opens with "Don't be afraid to launch a product without machine learning," and says that if ML would give you a 100% boost, a gets you 50% of the way there. The problem-framing course adds the next step: optimize your non-ML solution first, because it's the benchmark that tells you whether ML is worth it.
So a heuristic gives you two things: a product that works today, and a number that any future model has to beat on the same data.
When a simpler approach is safer
Google's People + AI Guidebook lists cases where AI is probably not the better choice: when predictability matters most, when the information users need barely varies, when a costly error outweighs a small gain in success rate, when people need full transparency into what the code does, and when shipping fast and cheap matters more than what AI would add.
When machine learning does win
The same Rules of ML that tells you to start without ML says the opposite once the heuristic grows: choose machine learning over a complex heuristic, because a learned model is easier to update and maintain. When the rules pile up, interact and keep needing exceptions, and you have good labeled data, that's the moment to switch.
Question
Start with a rule
Consider machine learning
Can someone write the logic down?
Yes: a policy, a formula, a regulation
No: pixels, free text, many weak signals
Labeled data
Little, or labels a rule produced
Plenty, consistent, available at prediction time
Cost of a wrong answer
High, and every decision must be explained
Tolerable, with a fallback or a human in the loop
How the logic changes
When someone updates the policy
As behavior shifts, faster than people rewrite rules
Size of the heuristic
A few readable conditions
A growing pile of exceptions nobody wants to touch
How to apply it in your project
Ask how the decision is made todayBefore collecting data, ask the domain owner. If the answer is a policy, a formula or a short checklist, implement it and unit test its boundaries.
Ship the heuristic and measure itTrack metrics from day one, as Rules of ML recommends before any model exists. What the heuristic catches and misses is the benchmark for everything that follows.
Check the data before the modelWho produced the labels? Are all inputs available at prediction time? Are there enough consistent examples? If any answer is no, a model won't fix it.
Switch when the rules get complexWhen the heuristic becomes a pile of special cases, train a simple model, compare it with the heuristic on the same held-out data, and feed the heuristic in as a feature.
Price the model, not just its accuracyCount retraining, monitoring and a fallback for when it's wrong. If the gain over the heuristic doesn't pay for that upkeep, keep the rule.
Key takeaways
A model learns an approximation from examples; when you can write the logic, code is exact, testable and cheap to change.
Start with a heuristic: it ships sooner and becomes the baseline any model must beat.
If your labels came from a rule, a model can at best copy that rule, with errors at its edges.
Machine learning wins when the rules are unknown or too complex to maintain and you have good data; then reuse the heuristic as a feature.
التعليقات (0)