Home / Insights / AI and Machine Learning

AI and Machine Learning

Anomaly Detection: When Rules Are Enough and When Machine Learning Pays Off

Spotting unusual transactions, sensor readings or behaviour sounds like a natural job for machine learning, but many anomaly problems are better served by well-designed rules. This guide helps you choose the right approach and design the alert workflow that determines whether any of it is useful.

TopicsAI and Machine LearningBusiness Operations and Integration

Key takeaways

  • Start by writing down what “abnormal” means. If experts can state it precisely, rules are often cheaper and easier to explain.
  • Unsupervised methods find unusual data, not necessarily problems. Expect to tune them against reviewer feedback.
  • Once you have enough confirmed incidents, a supervised model usually outperforms unsupervised scoring on the cases you care about.
  • The alert workflow matters as much as the model. Budget the review team’s capacity and design for it.
  • Most production systems combine rules, an anomaly score and human review rather than relying on one technique.

Operations, finance and engineering teams all have versions of the same request: tell us when something unusual happens. A payment that does not fit a customer’s pattern. A machine whose vibration drifts before it fails. A warehouse whose pick rate drops overnight. A sudden spike in refunds from one store.

Anomaly detection is one of the services in our machine learning development work, and one where we often recommend starting with something simpler than a model. This article explains how to choose between rules, unsupervised and supervised approaches, and how to design the alert workflow around them. For fraud specifically, where decisions affect customers directly, see our article on AI agents for fraud detection, which focuses on human-controlled decision workflows.

First, define what abnormal means in your context

Before choosing any technique, answer three questions with the people who will act on alerts:

  • What would you do if alerted? If there is no action, there is no use case. An alert that nobody acts on is noise.
  • Can you describe the bad cases? “Any refund over a set amount without a matching order” is a rule. “Something that looks off” is not.
  • Do you have examples? Records of past incidents, confirmed fraud, failures or errors with timestamps are the difference between a supervised and an unsupervised project.

The answers usually point clearly to one of three approaches.

Three approaches compared

ApproachWorks best whenStrengthsWeaknesses
Rules and thresholdsExperts can describe bad cases precisely; regulations define limitsTransparent, fast to build, easy to auditMiss new patterns; rule sets grow complex and brittle over time
Unsupervised anomaly scoringFew or no labelled incidents; patterns vary by entity or over timeCan surface unknown issues; no labels needed to startFlags unusual rather than harmful; needs tuning and review
Supervised classificationMany confirmed examples of the events you care aboutTargets the specific problem; measurable precision and recallNeeds labels; can miss novel patterns not in training data

Rules and thresholds

Rules are underrated. Static thresholds, rate limits, and checks against reference data catch a large share of obvious problems with no model at all. Rules also make good features for a later model. The weakness appears when rule sets grow into hundreds of overlapping conditions that nobody fully understands; at that point, Google’s Rules of Machine Learning suggests a learned model is easier to maintain than a complex heuristic.

Unsupervised anomaly scoring

Unsupervised methods learn what “normal” looks like and score how far each new record departs from it. Common techniques include Isolation Forest, which isolates observations using random splits so that anomalies tend to need fewer splits; Local Outlier Factor, which compares a point’s local density with that of its neighbours; and statistical approaches that assume roughly Gaussian data. It helps to distinguish outlier detection, where training data already contains anomalies, from novelty detection, where you train on clean data and flag new observations that differ.

The catch is that unusual is not the same as bad. A large legitimate order or a planned maintenance shutdown will score as anomalous. Unsupervised systems need reviewer feedback to become useful.

Supervised classification

When you have many confirmed incidents, a classifier trained to recognise them usually performs better on those cases than general anomaly scoring. Its performance can be measured with precision and recall at a chosen threshold, which makes the trade-off explicit. Our article on ML baselines and success metrics explains how to set those thresholds.

How production systems usually combine them

Real systems are layered. An illustrative design for monitoring supplier payments might look like this:

  1. Hard rules block or flag clear violations: a payment to a bank account changed in the last few days, duplicates of an existing invoice, amounts above approval limits.
  2. An anomaly score ranks remaining payments by how unusual they are for that supplier, considering amount, timing and frequency.
  3. A review queue shows the highest-scoring items to finance staff with the reasons for the flag.
  4. Reviewer outcomes (genuine issue, false alarm, needs follow-up) are stored as labels.
  5. A supervised model is trained once enough labelled outcomes accumulate, and the unsupervised score becomes one of its features.

A similar pattern works for sensor data in manufacturing: engineering limits as rules, a model of each machine’s normal behaviour for drift, and maintenance outcomes fed back as labels.

Designing the alert workflow and avoiding alert fatigue

The most common reason anomaly projects fail is not poor detection, it is too many alerts. When reviewers see mostly false alarms, they stop looking.

  • Budget review capacity first. If the team can review a fixed number of alerts per day, set the threshold to produce roughly that many, then improve precision over time.
  • Explain every alert. Show which features or rules triggered it and how the value compares with the entity’s normal range.
  • Group related alerts. Ten alerts from one sensor in an hour are one incident.
  • Capture outcomes in one click. Labelling must be part of the review screen, not a separate task.
  • Separate severity levels. Some anomalies warrant an immediate page; most belong in a daily queue.
  • Review the alert mix regularly. Retire rules that only produce false alarms and add rules for patterns reviewers keep spotting.

Data, drift and ongoing operation

Anomaly detection is especially sensitive to changes in the underlying business. A new product line, a pricing change or a new sensor firmware can make large parts of normal activity look anomalous overnight. Plan for:

  • Per-entity baselines. What is normal for one customer, store or machine may be abnormal for another.
  • Seasonality. Weekly and yearly patterns should be part of “normal”.
  • Scheduled retraining and threshold review, plus alerts when the volume of anomalies changes sharply, which often signals a data problem rather than a real wave of incidents.
  • Data quality checks upstream. Missing or duplicated records frequently masquerade as anomalies.

These are standard MLOps concerns, but they bite earlier with anomaly detection because the model’s definition of normal is the product.

Frequently asked questions

Can we start anomaly detection with no labelled incidents?

Yes. Start with rules for known cases and unsupervised scoring for the rest, and design the review screen to capture outcomes. Those outcomes become the labels for a supervised model later.

How do we measure an unsupervised anomaly detector?

Track the share of reviewed alerts that turn out to be genuine, and test on any historical incidents you can find. Without some labelled cases, measurement is limited, which is another reason to capture reviewer outcomes.

Is anomaly detection the same as fraud detection?

Fraud detection is one application. Anomaly detection also covers equipment monitoring, data quality, operational performance and security. The techniques overlap, but fraud decisions affect customers and need stronger review controls.

Should anomaly detection run in real time?

Only if the action must be immediate, such as blocking a payment. Many operational use cases work well with hourly or daily batches, which are simpler and cheaper to run.

Sources and methodology

Guidance reflects PoliteTech delivery experience. The external references below informed specific points in this article.

  1. scikit-learn: Novelty and outlier detection — Supports the distinction between outlier and novelty detection and the descriptions of Isolation Forest and Local Outlier Factor.
  2. Google for Developers: Rules of Machine Learning — Supports launching with simple heuristics and moving to ML when heuristics become complex.

Are your alerts catching real problems or just unusual data?

We can review your current rules and data, then design a layered anomaly detection approach with a review workflow your team can sustain.