Z-Score Thresholds vs. Isolation Forest: What Each Catches in Expense Fraud
This z-score vs isolation forest comparison for expense fraud detection pits a simple amount-based rule against a multivariate Isolation Forest, to see which anomalies each one actually catches.
Expense-fraud detection often begins with a simple rule:
Flag unusually large claims.
One common way to formalise that rule is with a z-score. If an expense amount is several standard deviations above the average, send it for review.
There is a good reason this approach remains popular.
It is cheap, transparent and easy to explain.
But it also asks a very specific question:
Is this amount unusual compared with other amounts?
Fraud is not always unusual in that way.
A ₹25,000 hotel bill may be perfectly normal for one employee travelling internationally and suspicious for another employee who normally submits local expenses.
A ₹5,000 meal may not be globally extreme, but it may be unusual for that employee, category, location or time.
That raises a more interesting question:
What happens when an expense is suspicious because of its context rather than simply because its amount is extreme?
To explore that question, I compared two anomaly-detection approaches on the same synthetic expense dataset:
- a univariate z-score threshold, and
- a multivariate Isolation Forest.
The objective is not to prove that one algorithm is universally better.
It is to understand what kinds of anomalies each method is capable of seeing.
1. Two Different Definitions of “Unusual”
A z-score measures how far a value lies from the mean in units of standard deviation.
For an expense amount (x):
z = (x − μ) / σ
where:
- μ is the mean expense amount,
- σ is the standard deviation.
A rule such as:
|z| > 3
flags observations that are far from the centre of the amount distribution.
This works well when suspicious transactions are also extreme-value transactions.
For example:
₹1,800₹2,100₹1,950₹2,300₹2,050₹48,000
The ₹48,000 expense stands out immediately.
But consider another example.
Suppose an employee usually submits:
- ₹500–₹1,500 for meals,
- ₹2,000–₹5,000 for local travel,
- and rarely travels internationally.
Now imagine a ₹12,000 entertainment expense submitted late at night from an unusual location.
₹12,000 may not be extreme across the entire company.
But the combination of employee, category, amount, time and location may be unusual.
A univariate amount z-score cannot see those relationships.
A multivariate anomaly detector potentially can.
2. The Experiment
To make the comparison measurable, I generated a synthetic expense dataset containing normal transactions and deliberately injected anomalies.
The synthetic design gives us something real expense data rarely provides:
known ground truth.
We know which transactions were generated as normal and which were deliberately generated as anomalies.
The anomalies were divided into two broad categories.
Point anomalies
These are expenses whose amount itself is unusually large.
They are the type of anomaly a z-score should be good at detecting.
Contextual anomalies
These are expenses whose amount may not be globally extreme but whose combination of features is unusual.
Examples include unusual combinations of:
- employee,
- expense category,
- amount,
- timing,
- or other contextual variables represented in the dataset.
This second category is deliberately important.
It tests something a univariate amount-based rule is not designed to model.
3. An Important Fairness Note
Before comparing the models, there is an important limitation to state clearly.
The contextual anomalies in this synthetic experiment are deliberately created from relationships among multiple variables.
Those variables are supplied to the Isolation Forest.
The z-score, by contrast, receives only the expense amount.
So the experiment is not a neutral contest in which both methods receive identical information and Isolation Forest somehow discovers more fraud.
The experiment deliberately asks a different question:
What happens when anomalies exist in relationships that a univariate amount rule cannot represent?
Isolation Forest has access to those relationships.
The amount z-score does not.
Therefore, if Isolation Forest performs better on contextual anomalies, that result should be interpreted as evidence of the structural advantage of multivariate information for this type of anomaly, not as proof that Isolation Forest will outperform z-score rules by the same margin on real corporate expense data.
That distinction matters.
4. Method 1: Z-Score Thresholding
The z-score approach is deliberately simple.
For each expense amount:
- calculate the mean,
- calculate the standard deviation,
- convert the amount to a z-score,
- flag sufficiently extreme observations.
Conceptually:
z = (amount - mean_amount) / std_amount
flag = abs(z) > threshold
The strengths are obvious:
- inexpensive,
- fast,
- deterministic,
- easy to audit,
- easy to explain.
If a compliance reviewer asks:
“Why was this expense flagged?”
the answer can be:
“Its amount was more than three standard deviations from the mean.”
That level of interpretability has genuine operational value.
But the weakness is equally clear.
The rule sees:
amount
It does not inherently see:
amount + employee + category + timing + context
unless those relationships are explicitly engineered into separate rules.
5. Method 2: Isolation Forest
Isolation Forest approaches anomaly detection differently.
Instead of asking how many standard deviations an observation lies from a mean, it repeatedly partitions the feature space using randomly selected features and split values.
The intuition is elegant:
Unusual observations tend to be isolated using fewer random partitions than common observations.
Isolation Forest was introduced by Liu, Ting and Zhou specifically as an anomaly-detection method based on isolation rather than estimating a normal-data density [1].
In this experiment, the model receives multiple expense-related features.
That gives it the possibility of identifying unusual combinations even when the amount itself is not globally extreme.
6. Keep the Alert Budget Comparable
There is another problem when comparing anomaly detectors.
Suppose the z-score flags:
50 transactions
while Isolation Forest flags:
500 transactions.
Isolation Forest might catch more fraud simply because it sends ten times as many cases for review.
That would not be a very useful comparison.
In a real finance team, investigation capacity is limited.
So the experiment uses a matched alert budget.
Both methods are evaluated while flagging approximately the same number of transactions.
That makes the comparison more operationally meaningful.
The question becomes:
If the investigation team can review roughly the same number of alerts, what kind of anomalies does each method surface?
7. Evaluation Metrics
Accuracy is not particularly useful for rare-event anomaly detection.
If fraud represents only a small fraction of transactions, a system that predicts:
“Everything is normal”
can achieve high overall accuracy while detecting no fraud at all.
So this experiment focuses on more informative metrics.
Precision
Of all transactions flagged:
How many were actually injected anomalies?
Precision = TP / (TP + FP)
Recall
Of all injected anomalies:
How many did the detector identify?
Recall = TP / (TP + FN)
F1 score
F1 balances precision and recall:
F1 = 2 × (Precision × Recall) / (Precision + Recall)
ROC-AUC
ROC-AUC evaluates how well a continuous anomaly score ranks anomalous observations above normal observations across thresholds.
This distinction is important.
ROC-AUC should be calculated from the continuous anomaly score produced by each method, not from the final binary alert flag.
For the z-score, a natural continuous anomaly score is the magnitude of the z-score:
|z|
For Isolation Forest, the model’s continuous anomaly score can be used, with its direction transformed where necessary so that larger values consistently mean “more anomalous.”
Only after defining the score direction consistently should ROC-AUC be calculated.
8. What the Experiment Found
The most interesting result was not simply that one method achieved a higher overall score.
It was which anomalies each method detected.
The amount z-score performed as expected on large point anomalies.
When an expense was extreme in the dimension the rule actually measured — amount — the method had a strong signal.
Its weakness appeared with contextual anomalies.
In this run, the z-score detected only:
3.6% of the contextual anomalies.
That result should be described carefully.
It does not mean the detector performed at “random luck.”
No random baseline was defined or measured in this experiment.
The defensible interpretation is:
The amount-based z-score detected very few contextual anomalies in this run, which is consistent with the fact that it does not model the multivariate relationships used to construct those anomalies.
That is the result the experiment actually supports.
9. Why Isolation Forest Sees Something Different
Suppose these two transactions occur:
Transaction A
Employee: frequent international traveller
Category: Hotel
Amount: ₹22,000
Location: Singapore
Transaction B
Employee: office-based employee
Category: Entertainment
Amount: ₹22,000
Location: unusual for that employee
From the perspective of a global amount z-score:
₹22,000 = ₹22,000
The contextual difference disappears.
A multivariate detector receives a richer representation.
It can potentially learn that:
₹22,000 + hotel + frequent traveller
occupies a different region of feature space from:
₹22,000 + unusual category + unusual employee pattern
This does not mean Isolation Forest “understands fraud.”
It does not.
It identifies unusual observations according to the structure of the features it receives.
A human or downstream investigation process must still determine whether an anomaly is legitimate, erroneous or fraudulent.
10. A Crucial Distinction: Anomaly Detection Is Not Fraud Detection
This distinction deserves emphasis.
Isolation Forest detects:
anomalies
not:
fraud
An unusual transaction may be completely legitimate.
For example:
- an executive travelling unexpectedly,
- an emergency purchase,
- a one-time conference registration,
- an unusual but approved hotel stay,
- a new employee with little historical data.
Likewise, sophisticated fraud may look statistically normal.
A fraudulent actor who understands company spending patterns may deliberately remain inside expected ranges.
Therefore:
Anomaly detection should usually be treated as a prioritisation mechanism for investigation, not as proof of fraud.
That distinction becomes especially important in financial and compliance applications.
11. Why the Z-Score Still Matters
After seeing stronger contextual detection from a multivariate method, it would be easy to conclude:
“Just replace z-score rules with Isolation Forest.”
I do not think that is the right lesson.
Z-score rules have several advantages.
They are transparent
A reviewer can understand why a transaction was flagged.
They are cheap
They require almost no computational infrastructure.
They are deterministic
The same input and threshold produce the same decision.
They are easy to govern
Thresholds can be documented and approved.
They are effective for obvious point anomalies
If a ₹1,50,000 expense appears in a category where most transactions are ₹2,000, a simple statistical rule may be exactly what is needed.
The problem is not that z-scores are bad.
The problem is expecting a one-dimensional rule to detect a multidimensional anomaly.
12. Why Isolation Forest Is Not Automatically Better
Isolation Forest also introduces trade-offs.
Its alerts can be harder to explain.
Performance depends on:
- feature selection,
- feature encoding,
- contamination assumptions,
- preprocessing,
- hyperparameters,
- training data,
- and the structure of normal behaviour.
Poor features can produce poor anomalies.
And a detector can learn operational quirks that have nothing to do with fraud.
A model that flags unusual transactions efficiently but overwhelms investigators with irrelevant cases is not necessarily useful.
The real metric is not:
“How sophisticated is the algorithm?”
It is closer to:
“How many genuinely useful investigations do we generate for the review capacity available?”
13. The Better Architecture May Be Hybrid
The experiment suggests that a practical expense-monitoring system does not necessarily need to choose between rules and machine learning.
A more useful architecture may combine them.
Layer 1 — Deterministic rules
Catch obvious policy violations:
- amount above approved limits,
- prohibited merchants,
- duplicate invoices,
- weekend claims where policy forbids them,
- missing documentation.
Layer 2 — Statistical rules
Catch straightforward numerical outliers:
- extreme amounts,
- unusual frequencies,
- unusually large category totals.
Layer 3 — Multivariate anomaly detection
Identify unusual combinations:
- employee + category,
- employee + amount,
- merchant + timing,
- geography + spending behaviour,
- combinations that are individually normal but collectively unusual.
Layer 4 — Human investigation
Determine whether the flagged behaviour is:
- legitimate,
- erroneous,
- policy-breaking,
- or potentially fraudulent.
That layered approach combines interpretability with broader anomaly coverage.
14. What This Experiment Does NOT Prove
The experiment does not prove:
Isolation Forest is the best fraud-detection algorithm.
It does not prove:
Isolation Forest will achieve the same performance on real corporate expenses.
It does not prove:
Z-score thresholds are obsolete.
It does not prove:
Every anomaly detected by Isolation Forest is fraud.
And it does not establish a production-ready fraud system.
The experiment uses synthetic data, and the contextual anomalies are deliberately generated using relationships among features available to the multivariate model.
Therefore, the appropriate conclusion is narrower:
When suspicious behaviour is defined by relationships among multiple variables, a detector that receives those variables can identify patterns that a univariate amount threshold cannot represent.
That is what the experiment demonstrates.
15. Limitations
There are several important limitations.
Synthetic data
Real expense behaviour is messier.
Employees change roles. Travel patterns change. New merchants appear. Policies differ across countries. Legitimate unusual events happen.
Synthetic data cannot reproduce all of that complexity.
Designed contextual anomalies
The contextual anomalies were intentionally constructed from multivariate relationships.
Because Isolation Forest receives those variables and the z-score does not, the experiment structurally favours the multivariate detector for that class of anomaly.
This is intentional—it is what the experiment is designed to test—but it limits how broadly the performance difference should be generalised.
Single experimental run
A single random seed can produce a result that looks more stable than it really is.
A stronger study would repeat the entire experiment across multiple random seeds and report:
mean ± standard deviation
for the important metrics.
Feature representation
Isolation Forest can only use the information represented in its features.
Changing how categories, employees, time or other contextual variables are encoded may change the results.
No investigation cost model
A false positive is not free.
Someone has to review it.
A production study should therefore include metrics such as:
fraud detected per 100 investigations
or:
value recovered per investigation hour
rather than focusing only on model-level metrics.
16. A Better Follow-Up Experiment
The next version of this experiment should move beyond a single synthetic run.
I would test:
Multiple random seeds
For example:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Then report:
mean ± standard deviation
for precision, recall, F1 and ROC-AUC.
Multiple fraud rates
Test what happens when anomalies represent:
10% → 5% → 1% → 0.5%
Real fraud detection often operates under severe class imbalance.
Multiple alert budgets
Compare:
top 0.5% → 1% → 2% → 5%
This would show how detector quality changes as the investigation team is allowed to review more cases.
A random-ranking baseline
This would allow statements such as:
“The detector performs better than random ranking.”
That comparison should be measured rather than assumed.
Additional detectors
Compare:
- z-score,
- robust z-score,
- Isolation Forest,
- Local Outlier Factor,
- One-Class SVM,
- and perhaps a supervised model when labelled fraud data are available.
At that point, the experiment becomes much closer to a proper anomaly-detection benchmark.
17. The Bigger Lesson
The most useful result from this experiment is not:
“Isolation Forest beats z-score.”
That is too simplistic.
The more interesting lesson is:
Different anomaly detectors encode different definitions of abnormality.
A z-score asks:
“Is this number unusual?”
Isolation Forest can ask something closer to:
“Is this combination of values unusual relative to the rest of the data?”
Neither question is universally better.
They are different questions.
And if the fraud we care about is contextual, the features supplied to the detector may matter as much as the algorithm itself.
That leads to a broader principle:
Before choosing an anomaly-detection algorithm, define what kind of anomaly you are actually trying to detect.
Point anomaly?
Contextual anomaly?
Collective anomaly?
Policy violation?
Behavioural change?
The answer should determine the detector—not the other way around.
Conclusion
Simple statistical rules remain useful.
They are transparent, cheap and effective for the kind of anomalies they are designed to detect.
But expense fraud can be contextual.
A transaction can look ordinary in isolation and unusual only when viewed in relation to:
- who submitted it,
- what it was for,
- when it occurred,
- where it occurred,
- and how that combination compares with normal behaviour.
That is where multivariate anomaly detection becomes useful.
The experiment does not show that Isolation Forest should replace z-score thresholds.
It shows something more practical:
A detector can only find patterns represented in the information it receives.
If we give a model only the amount, we should not be surprised when it misses anomalies defined by context.
The right question is therefore not:
“Which algorithm is better?”
It is:
“What kind of abnormal behaviour are we trying to find, and does our detector have the information required to see it?”
References and Further Reading
[1] Liu, F. T., Ting, K. M., & Zhou, Z.-H. (2008). Isolation Forest. Eighth IEEE International Conference on Data Mining.
The original Isolation Forest paper.
https://doi.org/10.1109/ICDM.2008.17
[2] Liu, F. T., Ting, K. M., & Zhou, Z.-H. (2012). Isolation-Based Anomaly Detection. ACM Transactions on Knowledge Discovery from Data, 6(1).
A more detailed treatment of isolation-based anomaly detection.
https://doi.org/10.1145/2133360.2133363
[3] scikit-learn. IsolationForest Documentation.
Implementation details and definitions for anomaly scoring in scikit-learn.
https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.IsolationForest.html
[4] Chandola, V., Banerjee, A., & Kumar, V. (2009). Anomaly Detection: A Survey. ACM Computing Surveys, 41(3).
A foundational survey covering point, contextual and collective anomalies.
https://doi.org/10.1145/1541880.1541882
Reproducibility and Interpretation Note
This experiment uses a synthetic dataset with known injected anomalies.
Contextual anomalies are deliberately generated from relationships among multiple variables available to the Isolation Forest but not to the univariate amount z-score. The experiment therefore demonstrates the structural difference between univariate and multivariate anomaly detection; it should not be interpreted as evidence that Isolation Forest will achieve the same relative performance on real expense-fraud datasets.
ROC-AUC should be calculated from each detector’s continuous anomaly score, with score direction normalised so that larger values consistently indicate greater anomalousness. Binary alert decisions should be evaluated separately using precision, recall and related threshold-dependent metrics.
The reported 3.6% contextual-anomaly recall is a measured result from this experimental run. It should not be characterised as “random” unless an explicit random baseline is calculated and compared.
Related Reading
- Paraphrased Benchmark Contamination Detection — the same simple-threshold-vs-structure-aware-detector trade-off, applied to contamination instead of fraud
- Honest Write-Up: The Law of Large Numbers Doesn’t Always Save You — another case where a standard statistical assumption quietly breaks down
- A Single-Feature Threshold Nearly Matches a Classifier’s Sensitivity — But Not Its False-Positive Rate — the same simple-rule-vs-model trade-off tested on a cancer-diagnosis dataset instead of fraud
