This is a method guide to two common approaches for transaction fraud detection: isolation forest, an unsupervised anomaly detector, and logistic regression, a supervised classifier. It explains what each does, how to evaluate them under severe class imbalance, how to pick an operating threshold, and how much data validation needs. It reports no results from any dataset.
Illustrative example with made-up numbers: Suppose a fraud system flags 1,200 transactions overnight and 47 of them are actual fraud. The other 1,153 are legitimate customers buying plane tickets, paying for hotel rooms, or making large purchases while traveling. Suppose the system stopped $18,000 in fraud losses but blocked $340,000 in legitimate revenue. These figures are invented to show the trade-off, not measured from any data.
This is the fraud detection trap: catch every fraudster and you destroy customer trust, miss too much fraud and the business suffers. The question is not only whether fraud can be detected, but whether it can be detected without blocking good customers.
The Real Question: Supervised or Unsupervised?
Before choosing an algorithm, think about experimental design. Fraud detection sits at an uncomfortable intersection: you have some labeled fraud data (chargebacks eventually reveal which transactions were fraudulent), but fraud patterns can evolve faster than you can retrain supervised models. Do you build a classifier on known fraud patterns, or do you detect anomalies that might represent novel tactics?
This is a question about what you are trying to catch. Logistic regression answers: "Does this transaction look like the fraud seen before?" Isolation forest answers: "Does this transaction look unusual compared to normal behavior?" The first approach requires confirmed fraud examples. The second can be trained on normal transactions alone.
A Typical Experimental Setup
Setup to consider: Transaction tables often hold anonymized or PCA-transformed features, plus a time field and an amount. Fraud is usually well under one percent of rows. A common design is to build a balanced training sample that keeps all fraud rows and a random subset of legitimate rows (with a fixed random seed for reproducibility), so models see enough positive signal during training. Isolation forest is available in R through packages such as solitude and in Python through scikit-learn. Logistic regression is available in base R through glm, with ROC and AUC computed through packages such as pROC.
Balanced sampling is critical for model training but creates an evaluation trap. In a balanced sample the fraud share might be several percent or more, while in production it may be a fraction of a percent. Every precision number computed on the balanced sample will be wildly optimistic. The sections below explain how to interpret results given this reality.
What You're Actually Optimizing For
Many fraud detection guides jump straight to ROC curves and AUC metrics. That is backwards. Before running experiments, define what you are willing to trade.
False positives (flagging legitimate transactions) cost customer trust and revenue. Block someone's card at a restaurant and they may switch banks. False negatives (missing fraud) cost chargeback fees, fraud losses, and potentially your merchant account if fraud rates get too high. The optimal operating point depends on these costs, not on statistical metrics.
Illustrative example with made-up numbers: suppose the average transaction value is $75 and the average fraud loss is $150. You could afford to flag about 2 legitimate transactions per fraud caught before losing money on the flags alone. But customer lifetime value matters more than single transactions. Suppose blocked customers churn at a 30% rate and average lifetime value is $2,400. Then each false positive carries a large expected cost, and the affordable ratio of false positives to frauds caught shrinks sharply. Run the math with your own numbers before choosing a threshold.
Fraud Prevalence: Balanced Sample vs Production
Class balancing is essential for training. With a raw fraud rate far below one percent, a logistic regression model would see a handful of positive examples and a huge number of negatives. The optimizer could reach very high accuracy by predicting "not fraud" for every transaction, learning nothing about fraud patterns.
Oversampling fraud cases to a higher prevalence forces the model to learn discriminative features. But for interpretation, every precision estimate from the balanced sample is inflated. When the model is deployed at the true, much lower fraud rate, precision falls by roughly the ratio of the two prevalences. A model showing high precision on the balanced sample can deliver very low precision in production.
This is why recall (sensitivity) and false-positive rate are the safer metrics on balanced samples. Recall carries over directly: if the model catches a given share of fraud in the balanced sample, it catches about the same share in production, assuming the sample is representative. Precision must be recalculated using Bayes' theorem once you know your production fraud rate.
The takeaway: balanced sampling solves the training problem but complicates evaluation. Always validate models on a holdout set that reflects true production prevalence, or adjust your precision estimates using the fraud rate you will actually encounter.
Reading Isolation Forest Anomaly Scores by Class
Isolation forest assigns anomaly scores by measuring how many splits are required to isolate each observation in a random forest structure. Outliers require fewer splits, while normal points require many. A box plot of anomaly score by class (fraud vs legitimate) shows how well the score separates them.
Expect some overlap. Isolation forest learns "normal" patterns during training, then flags deviations. But not all fraud is anomalous, since skilled fraudsters often mimic legitimate behavior. Conversely, not all anomalies are fraud, since legitimate customers making unusual purchases (a first international transaction, an unusually large purchase) also score high.
Look at the distribution shapes. A longer right tail for fraud means a subset of fraud is highly anomalous and will be caught at low false-positive rates. Tight clustering of legitimate transactions with few extreme scores means the filter is selective. Sophisticated fraud that blends in will be missed.
The practical implication: isolation forest works well as a first-pass filter in a multi-stage system. Flag the most anomalous slice of transactions for manual review or secondary model scoring. Do not rely on it alone, because it will miss fraud that mimics normal patterns, and a supervised model is needed to distinguish "unusual but legitimate" from "unusual because fraudulent."
Reading Logistic Regression Coefficients
A logistic regression coefficient is the change in the log-odds of fraud for a one-unit increase in a feature. A negative coefficient means higher values make fraud less likely, and a positive coefficient means higher values make fraud more likely. Exponentiating a coefficient gives an odds ratio. Check that the strongest coefficients are statistically significant (p-values below 0.05) and note both positive and negative predictors, since a mix of signs gives a more stable decision boundary than a rule that flags only extreme values.
When features are PCA components, the transformation prevents interpreting what each component means in business terms. Statistical significance and magnitude still show which patterns are stable and discriminative, but you cannot translate them into plain-language reasons. Interpretability is a real trade-off when features are anonymized.
For regulatory compliance, the coefficient table is your documentation. When a regulator asks "why did you flag this transaction?", you can point to specific features and their weights. This transparency is logistic regression's main advantage over isolation forest, which offers no interpretable feature importances beyond "it looked unusual." In financial services, explainability is often required.
ROC Curves: Comparing Models at the False-Positive Rate You Can Tolerate
The ROC curve plots recall (true-positive rate) against false-positive rate across thresholds, and AUC summarizes it in one number. A higher AUC means better ranking of fraud above legitimate transactions overall. But the summary hides the operating-point trade-offs that matter for deployment.
Instead of reading AUC, pick the false-positive rate you might actually use and read each model's recall at that point. A stricter threshold (lower false-positive rate) cuts false alarms but misses more fraud. A looser threshold catches more fraud but flags more legitimate customers, which only works if the intervention is low-friction, such as asking for an additional verification code rather than declining the transaction.
The ROC curve tells you what is possible, not what is optimal. Calculate your fraud loss per transaction, your revenue per transaction, and your churn rate from blocked transactions. Then find the false-positive rate where (fraud caught times fraud loss saved) exceeds (false positives times revenue lost plus customer churn cost). That is your operating threshold.
Precision-Recall Curves Under Class Imbalance
The precision-recall curve exposes what ROC curves can hide: performance under severe class imbalance. When positives are rare, a small false-positive rate can still swamp the true positives, and precision shows it. PR-AUC summarizes the curve, and it is more sensitive than ROC-AUC when fraud is rare.
Read the curve at the recall you need. Decide what share of fraud you must catch, then check precision at that recall. The number of false positives per fraud caught is 1/precision minus 1. If you review flagged transactions manually, that ratio drives your review workload.
A supervised model usually holds precision better than an unsupervised one at the same recall, because isolation forest knows "this transaction is unusual" but cannot distinguish "unusual because fraudulent" from "unusual because legitimate but rare." Logistic regression learns that distinction from labeled examples.
Remember that precision estimates from a balanced sample are inflated. To translate to production, use Bayes' theorem with the true prevalence: precision = recall x prevalence / (recall x prevalence + false-positive rate x (1 - prevalence)). With a fraud rate well below one percent, precision at a moderate false-positive rate can be very low even for a strong model. The relative advantage of one model over another can persist even when absolute precision is low.
Confusion Matrix at the F1-Optimal Threshold
A confusion matrix counts true positives, false negatives, true negatives and false positives at one threshold. The threshold that maximizes F1 (the harmonic mean of precision and recall) is a common default. From the four counts you can compute recall, precision and false-positive rate.
Illustrative example with made-up numbers: suppose a system processes 100,000 transactions per day with 0.2% fraud, so about 200 frauds and 99,800 legitimate transactions. Suppose that at the chosen threshold it catches 75% of fraud (150 frauds) and flags 2% of legitimate transactions (1,996). The review team then sees about 2,146 flags a day, of which about 7% are real fraud. If the average fraud loss is $180, the system prevents $27,000 in daily losses. If each flag costs $0.50 of analyst time, review costs about $1,073 a day. These numbers are invented to show the arithmetic, not results from any data.
Is such a system viable? It depends on review capacity and fraud losses. The missed frauds represent losses you are not preventing. Loosening the threshold catches more of them but raises false positives proportionally. Every fraud detection system makes this trade-off. The confusion matrix shows the consequences at one operating point, and you must calculate whether the economics work for your business.
Threshold Selection Reality Check: The "optimal F1 threshold" is optimal for F1-score, which weights precision and recall equally. This is almost never your business objective. If fraud losses per transaction are small relative to the lifetime value lost when a customer churns, you should weight precision much more heavily than recall. Do not optimize for F1. Optimize for (fraud losses prevented) minus (false positive costs). Calculate the threshold that maximizes this business metric, not a statistical metric.
Should You Use Isolation Forest or Logistic Regression?
Here is a decision framework based on how the methods work:
Use logistic regression when:
- You have enough confirmed fraud examples to train a stable model (a few hundred is a common rule of thumb, more is better)
- You need explainable predictions for compliance, since regulators want feature coefficients, not black-box scores
- You are willing to retrain regularly as fraud patterns evolve
- You need high precision at moderate recall
- False positives are expensive (customer churn, manual review costs)
Use isolation forest when:
- You lack labeled fraud data (the cold start problem for new merchants)
- You want to surface novel fraud patterns not seen in training data
- You are building a first-pass filter before a supervised model
- You need fast deployment without waiting for fraud labels
- You have high tolerance for false positives in exchange for broad coverage
Use both in a two-stage system:
- Stage 1: Isolation forest filters the most anomalous slice of transactions
- Stage 2: Logistic regression scores the filtered subset, using learned fraud patterns to separate unusual fraud from unusual legitimate
- This hybrid can cover both known and novel fraud while maintaining precision
Five Mistakes That Kill Fraud Detection Systems
These are common ways fraud detection breaks in production:
1. Optimizing AUC instead of business metrics. A model with a high AUC can still lose money if it operates at the wrong threshold. Calculate your fraud loss per transaction, customer lifetime value, and churn rate from false positives. Find the threshold where (fraud prevented x fraud loss) minus (false positives x churn cost) is maximized. That is the target, not maximum AUC.
2. Training on balanced samples, deploying without recalibrating. The fraud rate in a balanced training sample is far higher than the production rate, so precision estimates are inflated by about the same ratio. Recalibrate probability thresholds using a holdout set that reflects true production prevalence, or use Platt scaling or a prior correction to adjust probabilities after training.
3. Ignoring concept drift. Fraud patterns evolve, so a coefficient that is strong today can weaken as fraudsters adapt. Set up monitoring to track model performance weekly. When recall drops several percentage points or the false-positive rate rises, retrain. Regular retraining is standard, and high-fraud environments need more frequent updates.
4. Using isolation forest alone. Isolation forest says "this is unusual" but cannot say why. A customer's first international transaction is unusual. So is a stolen card used for cash advances. Both score high on anomaly metrics, but one is legitimate and one is fraud. You need a supervised model to learn this distinction, or you will block legitimate customers at unacceptable rates.
5. No experimental design for threshold selection. Do not pick a threshold based on retrospective data analysis alone. Run a controlled experiment: route a share of traffic to the new threshold for a couple of weeks, measure fraud losses and customer complaints, and compare to the control group. A/B test thresholds the same way you A/B test landing pages, with randomization, controls, and proper sample size calculations.
What Sample Size Do You Need to Validate a Fraud Model?
Before you deploy a fraud detection model, you need to measure its performance with adequate statistical power. Here is how to calculate the required sample size for validation.
Suppose you are testing whether your model achieves at least 80% recall at a fixed false-positive rate. Your null hypothesis is that recall is at most 75% (not good enough). Your alternative hypothesis is recall of at least 80% (acceptable performance). You want 80% power to detect this difference at the 0.05 significance level. These thresholds are an illustrative choice. Substitute your own.
For a one-sample proportion test, required sample size is n = (Zα + Zβ)2 x p(1-p) / δ2, where p is the expected proportion (0.80 recall), δ is the minimum detectable effect (0.05 difference), Zα = 1.96 for α=0.05, and Zβ = 0.84 for 80% power.
n = (1.96 + 0.84)2 x 0.80 x 0.20 / 0.052 = 7.84 x 0.16 / 0.0025, which is about 502 fraud cases needed in your validation set.
Illustrative example with made-up numbers: suppose fraud prevalence is 0.2%. Then you need about 502 / 0.002 = 251,000 total transactions to see 502 frauds. If you process 100,000 transactions per day, that is roughly three days of data. Do not deploy on much smaller samples, because you will lack the power to detect whether the model actually works.
How to Interpret Your Results
When you run this kind of analysis on your own transaction data, here is how to read the outputs:
Fraud Prevalence Chart: Compare your training sample fraud rate to production fraud rate. If you have balanced your sample (recommended), expect a much higher fraud rate in training data. This is correct for model training, but remember to recalibrate thresholds before deployment. If your training fraud rate is close to the production rate, the model may underfit, so consider upsampling fraud cases.
Anomaly Score Distribution: Look for separation between fraud and legitimate distributions. If the median anomaly scores barely differ, isolation forest is not finding useful patterns, and your fraud may be too similar to legitimate transactions. If fraud scores extend well beyond the legitimate range, you have a clear anomaly signal and isolation forest will work well as a first-pass filter.
Logistic Coefficients: Check that top coefficients are statistically significant (p below 0.05). If your strongest feature has a small absolute coefficient, you are looking at weak signals, so expect lower precision in production. Large coefficients with very small p-values indicate strong discriminative features. Note which features are positive vs negative predictors, since a mix gives a more stable decision boundary.
ROC Curve: Ignore the AUC summary. Find the false-positive rate you can tolerate, then read off each model's recall at that rate. That is your deployment performance. If the supervised model catches many more percentage points of fraud than isolation forest at your target rate, supervised learning is worth the labeling cost. If the gap is small, isolation forest's label-free advantage may outweigh the performance edge.
Precision-Recall Curve: This is your real-world performance predictor under class imbalance. Decide what recall you need, then check precision at that recall. Remember precision estimates from balanced samples are inflated, so scale them to the production prevalence with Bayes' theorem. If adjusted precision is very low, you will flag many transactions per fraud caught, so assess whether your review process can handle that volume.
Confusion Matrix: Calculate total cost: (False Negatives x Fraud Loss per Transaction) + (False Positives x Customer Churn Cost). Compare to the baseline of catching zero fraud. If net benefit is positive and your review team can handle the flagged volume, deploy at this threshold. If false positives dominate costs, tighten the threshold (accept lower recall to gain precision). Run these calculations for several thresholds and pick the one that maximizes net benefit.
Post-Deployment Monitoring: Model performance will degrade. Set up weekly monitoring of these metrics: (1) recall on confirmed frauds, (2) false-positive rate on a random sample of flagged transactions, (3) review queue size. If recall drops or the false-positive rate rises beyond tolerances you set in advance, retrain using recent fraud examples. Fraud patterns evolve, and the model must evolve with them.
Your turn
Bring your own data and the question you actually need answered.
MCP AnalyticsData science by email Send us your data and your question, and we will reply. ds@mcpanalytics.ai
Frequently Asked Questions
Should I use isolation forest or logistic regression for fraud detection?
Use logistic regression when you have labeled fraud data and need explainable predictions for compliance, since its coefficients show which features drive risk. Use isolation forest when you lack labeled examples or want to surface novel patterns, since it learns what normal looks like without labels but offers less transparency for regulatory review. Many systems use both in two stages.
What false-positive rate should I target for fraud detection?
It depends on what happens to a flagged transaction. Automated blocking needs a low false-positive rate because customer friction is costly. Soft interventions such as step-up authentication can tolerate a higher rate. Set the rate from your own fraud loss per transaction, revenue per transaction and churn from blocked customers, not from a fixed rule of thumb.
How much data do I need to validate a fraud model?
Validation is limited by the number of confirmed fraud cases, not total transactions. A one-sample proportion power calculation gives the number of fraud cases needed to detect a chosen recall target, and dividing by your fraud prevalence gives the number of transactions to collect. Unsupervised methods can start from unlabeled data, but measuring their performance still requires labeled fraud examples.
Why does precision matter so much in fraud detection?
Low precision means blocking legitimate customers, which costs trust and revenue. Because fraud is rare, precision falls sharply when prevalence is low, even for a strong model. Precision measured on a balanced training sample is inflated, so recompute it at your production fraud rate using Bayes' theorem before judging a model.
Can isolation forest detect new types of fraud that were not in training data?
That is its main advantage. Isolation forest learns what normal transactions look like, then flags anything abnormal regardless of whether it matches known fraud patterns. The cost is more false positives, because legitimate unusual transactions such as a large purchase while traveling also look abnormal. Use it as a first-pass filter, then a supervised model to score the flagged transactions.