How Does Machine Learning Detect Fraud?
Machine learning fraud detection scores every transaction using learned fraud patterns and anomaly detection. See why 99% accuracy can catch nothing, a worked precision and recall example, and runnable code.
Short answer: Machine learning fraud detection uses models trained on past transactions to give each new transaction a risk score, so suspicious ones can be blocked, checked or sent to a human. It combines supervised classification, which learns from labelled fraud cases, with anomaly detection, which flags unusual behaviour that nobody has labelled yet.
How does machine learning detect fraud?
Machine learning detects fraud by learning what normal and fraudulent activity look like and scoring each new event against that. A typical pipeline has five steps:
Collect events: payments, logins, account sign-ups, insurance claims.
Build features: turn each event into numbers the model can use.
Score: the model outputs a probability or risk score, often within a fraction of a second.
Decide: compare the score with thresholds: allow, ask for extra verification, block, or send to review.
Learn: confirmed outcomes become new labels for the next version of the model.
Supervised classification vs anomaly detection: which is used?
Most fraud systems use both supervised classification and anomaly detection, often alongside hand-written rules, because each covers the others' blind spots.
Approach | Learns from | Good at | Weak at |
|---|---|---|---|
Supervised classification | Past events labelled fraud or not fraud | Catching known fraud patterns | New tricks; labels can arrive weeks late |
Anomaly detection | Mostly normal data, no labels needed | Spotting new, unusual behaviour | Unusual but honest events cause false alarms |
Rules | Experts writing conditions | Clear, explainable known cases | Rigid and easy for fraudsters to work around |
Supervised fraud detection is a classification problem with two classes. Anomaly detection belongs to unsupervised learning, described in types of machine learning.
What features does a fraud detection model use?
Fraud detection features usually compare an event with the customer's own history, because "unusual for this person" matters more than "large". Common examples:
Amount compared with the customer's usual amount.
Time of day and day of week.
New device, new location or a sudden change of location.
Velocity: how many transactions in the last few minutes or hours.
Merchant type, account age, and whether details such as the address were changed recently.
Designing such features is often the biggest win; see what feature engineering is.
Why is accuracy misleading for fraud detection?
Accuracy is misleading for fraud detection because fraud is rare, so a model can score high accuracy while catching nothing. This is called class imbalance. Take 1,000 transactions, of which 10 are fraud.
Model A says "not fraud" every time. It is right on 990 of 1,000 transactions, so its accuracy is 99%. It catches zero fraud: its recall is 0 of 10, or 0%.
Model B flags 25 transactions, and 8 of those are real fraud:
Really fraud | Really normal | |
|---|---|---|
Model B says fraud | 8 (true positives) | 17 (false positives) |
Model B says normal | 2 (false negatives) | 973 (true negatives) |
Accuracy = (8 + 973) / 1,000 = 98.1%, lower than Model A.
Precision = 8 / 25 = 32%: of the flagged transactions, about one in three is fraud.
Recall = 8 / 10 = 80%: it catches 8 of the 10 fraud cases.
Model B has lower accuracy but is far more useful. That is why fraud teams look at precision and recall, explained in precision, recall and F1 score, and choose a threshold that balances missed fraud against annoyed customers.
What does anomaly detection look like in code?
This runnable example uses scikit-learn's IsolationForest on made-up data: 990 ordinary transactions and 10 unusual ones. No labels are given to the model.
import numpy as np
from sklearn.ensemble import IsolationForest
rng = np.random.default_rng(0)
# 990 ordinary transactions: amount and hour of the day
normal = np.column_stack([rng.normal(40, 15, 990).clip(1), rng.integers(8, 22, 990)])
# 10 unusual ones: large amounts late at night
odd = np.column_stack([rng.normal(900, 100, 10), rng.integers(0, 5, 10)])
X = np.vstack([normal, odd]) # rows 990-999 are the unusual ones
model = IsolationForest(contamination=0.01, random_state=0)
labels = model.fit_predict(X) # -1 = looks unusual, 1 = looks normal
flagged = np.where(labels == -1)[0]
print("Flagged rows:", flagged)
print("Unusual rows caught:", (flagged >= 990).sum(), "of 10")IsolationForest works on the idea that unusual points are easier to separate from the rest. The contamination=0.01 setting tells it to flag about 1% of rows. Run it and check how many of the 10 unusual rows appear in the flagged list. Real data is much messier than this toy example, which is why flagged events go to review instead of being blocked automatically.
Why does fraud detection still need human review?
Fraud detection needs human review because models make two costly kinds of error: missed fraud loses money, and false alarms block honest customers. Analysts check borderline cases, their decisions become new training labels, and they notice new schemes early. Fraudsters also change tactics when they are blocked, so a model trained on last year's patterns slowly gets worse unless it is retrained. Teams should also check that error rates are not much higher for some groups of customers than others.
Common mistakes
Reporting accuracy on imbalanced data.
Random train/test splits on time-ordered data. Train on older events and test on newer ones, or the model sees the future.
Ignoring imbalance instead of using class weights, resampling or a tuned threshold.
Training once and never updating while fraud patterns change.
Giving reviewers a score with no reasons. Show which features raised the risk.
Frequently Asked Questions
What is class imbalance in fraud detection?
Class imbalance means one class is much rarer than the other, as fraud is compared with normal transactions. It makes accuracy misleading and pushes models to ignore the rare class unless you correct for it.
Which algorithm is best for fraud detection?
There is no single best algorithm. Logistic regression and gradient-boosted trees are common for tabular transaction data, and anomaly detectors such as IsolationForest help with unknown patterns; compare them on your own data with precision and recall.
Can fraud detection work without labelled data?
Yes, partly. Anomaly detection needs no labels and can flag unusual events, but it cannot tell unusual from fraudulent, so human review and later labels are still needed.
What is a false positive in fraud detection?
A false positive is an honest transaction that the model flags as fraud. Too many of them annoy customers and overload reviewers, so teams tune the threshold to keep them manageable.
Key Takeaway
Machine learning fraud detection scores every event using learned patterns and unusual behaviour, then lets thresholds and people decide. Judge it with precision and recall, never accuracy alone, and keep retraining as fraud changes.
Ready to start? You will understand how models learn from data, how they are judged, and where they fail. Begin with the free course How AI Works: Foundations for Everyone.
Related articles
More in Machine Learning
What Is Cross-Validation? k-Fold Explained Simply
Cross-validation tests a model on several splits of the data and averages the scores. See k-fold on a tiny worked example and run it in scikit-learn.
5 min readDec 1, 2026What Is Data Labeling and Why Does AI Need It?
Data labeling adds the right answers to raw data so models can learn. See the main label types, how to measure labeler agreement, and how AI-assisted labeling works.
5 min readNov 30, 2026What Is Feature Engineering? Better Data for Better Models
Feature engineering turns raw data into inputs a model can learn from. See the common techniques, a runnable Python example, and the mistakes that cause data leakage.
4 min readNov 26, 2026Gradient Descent Explained Simply
How models learn by measuring error and stepping downhill, with a runnable Python example showing learning rate, steps and local minima.
5 min readNov 23, 2026What Is Computer Vision? How AI “Sees” Images
Computer vision lets AI work with images and video. See how a picture becomes numbers, how models learn to recognise things, the main tasks, and where it goes wrong.
5 min readNov 22, 2026What Is NLP (Natural Language Processing)?
NLP is how computers read and produce human language. See how it works, the main tasks, a small Python example, and how NLP relates to LLMs.
4 min readNov 20, 2026
Comments
Sign in to join the discussion.

