DEV Community

NARESH
NARESH

Posted on

I Tried Combining Fraud Datasets. Here’s What Went Wrong

Banner

I spent time designing how a checkout system should recover from failure. Then I started wondering: what if the real problem was a transaction that succeeded?

In my previous article, I shared how I built Orchestrix, a distributed e-commerce system where I explored transaction consistency, Saga orchestration, and failure recovery.

But completing that project left me with another question.

A checkout system could correctly reserve inventory, process payment, and complete an order without knowing whether the transaction was legitimate.

The payment might involve a stolen card, a compromised account, or suspicious activity that the checkout workflow was never designed to recognize.

That curiosity led me to build Vigilant, a personal fraud detection and risk evaluation system where I explored machine learning, behavioral signals, and rule-based evaluation.

I initially expected the difficult part to be training the fraud detection models. But my first experiments with combining different fraud datasets challenged that assumption.

What started as an ML experiment gradually became a much broader engineering problem.

This article is about the decisions that changed my approach, the experiments that didn't work as expected, and what I learned about evaluating fraud beyond simply training a model.


My first approach didn't work as expected

One of the first challenges in building an ML system is finding the right data. Since Vigilant was a personal project, I started with publicly available fraud datasets rather than collecting real transaction data.

I explored the credit-card fraud dataset and IEEE-CIS. Both contain fraudulent and legitimate transactions, but they describe those transactions differently.

The credit-card dataset primarily contains anonymized numerical features, while IEEE-CIS includes card information, device details, email domains, and other transaction attributes.

So why did I try combining them?

Having worked on ML models before, I thought a common feature representation might simplify training and inference. Instead of maintaining separate models, I wanted to experiment with a single model trained on the combined data.

I considered two approaches.

The first was taking the union of features, retaining all columns from both datasets. However, transactions from one source wouldn't necessarily contain the attributes available in another. That meant handling large numbers of missing values and ensuring the model didn't learn misleading patterns from those differences.

The second was taking the intersection of features, retaining only columns shared between the datasets.

At the time, this seemed more practical. I could build a common input structure without requiring every transaction to contain every possible feature.

But I had overlooked something important.

Both datasets contain features named V1, V2, and so on. In the credit-card dataset, these are anonymized components produced through Principal Component Analysis (PCA). In IEEE-CIS, similarly named columns represent different features engineered by Vesta.

The column names matched, but the information behind them didn't.

This meant I could create a dataset that looked structurally compatible while combining features with different meanings.

There was another problem. By keeping only shared columns, I was discarding potentially valuable information, including features that might help distinguish suspicious transactions within each dataset.

I went through the training process, experimented with the models, and tried improving the results through hyperparameter tuning. But the performance wasn't convincing.

Eventually, I realized I had spent too much effort trying to make the datasets fit together without questioning whether the resulting features still represented the information I wanted the model to learn.

That experiment didn't prove that a unified fraud model was impossible. A properly designed source-aware model could still be a reasonable solution.

It showed me that sharing a feature schema and sharing a meaningful feature representation are two very different things.


Why I stopped forcing everything into one model

After that experiment, I reconsidered how I wanted Vigilant to handle different types of transaction data.

I could continue working toward a unified model, introducing source-specific preprocessing and carefully handling missing features.

That was still a valid option. But I wanted to explore what would happen if each dataset retained its own feature representation.

This led me to think about how fraud models would work for different businesses.

Suppose two companies wanted to use the same fraud detection platform.

One might have detailed information about customer devices, account activity, and transaction history. Another might only have payment amounts, timestamps, and a limited set of customer attributes.

Their available data would influence the models they could realistically train.

A model developed for the first company couldn't automatically be applied to the second, because the required features might not exist.

So I started thinking about a different design.

What if Vigilant could support multiple fraud models instead of expecting every transaction to fit one model?

That was how I arrived at the idea of source-specific models and dynamic model routing.

Rather than building one model around a common set of columns, I could train separate models using the features available in each dataset.

The platform would then be responsible for selecting the appropriate model when a transaction arrived.

I also wanted the model-serving side to be flexible. If I trained a new model or introduced another dataset, I shouldn't have to redesign the entire fraud evaluation workflow.

Of course, this introduced trade-offs.

Maintaining multiple models meant managing separate preprocessing requirements, model versions, and input contracts. The system also needed a reliable way to identify incoming transactions and select a compatible model.

A unified model might be easier to operate in some situations, particularly when the underlying data is sufficiently consistent. Specialist models aren't automatically more accurate, either. That would require a controlled comparison.

For Vigilant, though, I wanted to explore the flexibility of treating models as replaceable components rather than tightly coupling the platform to a particular dataset.

That decision changed the problem I was solving. I now had to think about how the inference system could reliably connect an incoming transaction to a model trained to understand its features.


How I approached dynamic model routing in Vigilant

Conceptual model-routing flow. The feature-validation and explicit unavailable/review paths represent safeguards I would strengthen, rather than behavior verified across every current code path.

Once I decided to explore source-specific models, I needed a way to select the appropriate model for each incoming transaction.

I wanted to avoid hardcoding a particular model into the fraud evaluation workflow. If I trained a new model or introduced another source of transaction data, the system should be able to accommodate it without redesigning the inference pipeline.

The first step was identifying where the incoming data belonged.

In Vigilant, the ingestion service can use an explicitly provided source identifier. When that isn't available, it examines recognizable attributes in the transaction payload.

For example, fields such as TransactionAmt and P_emaildomain can help identify an IEEE-CIS-style transaction.

But this identification is heuristic. Some attributes overlap between datasets, and a matching field name doesn't guarantee that its meaning is compatible with the model.

That distinction matters because selecting a model and validating its inputs are two separate responsibilities.

A routing decision tells the system which model to consider. It doesn't automatically establish that the transaction contains every feature that model expects.

Making models replaceable

For the inference layer, I used ONNX to serve models through a common runtime.

Each model has an associated feature specification, and the inference service can load multiple ONNX artifacts.

I also used Valkey-backed champion pointers to identify the active model version for a particular source. This allowed me to explore changing the selected model without modifying the surrounding risk evaluation workflow.

However, there's an important limitation.

The inference implementation can align incoming fields with a model's expected features and substitute zeros for missing values.

That preserves the input shape, but it doesn't necessarily preserve the meaning of the data.

A missing transaction attribute and an attribute whose actual value is zero can represent completely different situations. Treating them as equivalent could produce a technically valid prediction based on misleading inputs.

I would strengthen this with source-specific preprocessing and explicit validation of required features before inference.

Another edge case is a transaction for which no suitable model exists.

Vigilant has a default source path, and its documented cold-start behavior can return a score of 0.0 when a model is unavailable.

That may allow the workflow to continue, but it introduces a risk: downstream logic could interpret the missing prediction as evidence of low fraud risk.

I would rather make model unavailability an explicit outcome, allowing the decision layer to apply a defined policy instead of silently treating it as a normal prediction.

These were the trade-offs I encountered while exploring dynamic model routing.

Supporting multiple models gave Vigilant more flexibility, but it also introduced responsibilities around source identification, feature compatibility, and failure handling.

The lesson for me was that a prediction can be mathematically valid while still being unreliable because the wrong data was sent to the model.


Why a fraud score wasn't enough

While experimenting with the models, I started thinking about another problem.

Suppose a model evaluates a transaction worth ₹5,000 and returns a relatively low fraud score.

On its own, the transaction might look perfectly normal.

But what if the same account had attempted 15 transactions in the previous minute, using different cards or devices?

The transaction amount hasn't changed, but the surrounding behavior tells a different story.

A model can only evaluate the information available to it. If recent transaction activity isn't included in its features, it cannot recognize those patterns.

That made me explore additional signals beyond individual transaction predictions.

One was transaction velocity, which measures how frequently an account, card, or device performs certain actions within a time window.

In Vigilant, I experimented with a dedicated velocity service using sliding windows to track recent transaction activity. This could help identify unusually frequent payments or repeated attempts within a short period.

I also introduced deterministic rules for conditions such as transaction thresholds and velocity limits.

But neither approach is perfect. A sudden increase in transaction activity might indicate fraud, or it might simply be a legitimate customer making several purchases.

Another area I explored was graph-based analysis.

Two transactions might appear unrelated individually but share a device, IP address, or another identifier. Examining these relationships can reveal patterns that aren't obvious when looking at transactions in isolation.

In Vigilant, I explored graph relationships primarily as additional context for investigation, rather than assuming every graph query belonged in the immediate scoring path.

These experiments changed how I thought about fraud evaluation.

The ML model could provide one risk signal, while velocity checks, deterministic rules, and other contextual information could contribute additional evidence.

The challenge was deciding how to interpret those signals together without treating every unusual transaction as fraudulent.

A fraud score is a prediction. Whether to allow, review, or block a transaction is a separate decision.


What the experiments actually told me

One of the most useful lessons from Vigilant came from an experiment that had little to do with choosing an ML algorithm.

Since I had built Orchestrix before Vigilant, I initially considered using its transaction data to train a fraud detection model.

But Orchestrix was a personal e-commerce project. It had only a limited number of orders, nowhere near enough data for the kind of training and evaluation I wanted to explore.

So I wrote a script to generate synthetic transactions.

I spent almost half a day improving the randomizer, generating different amounts, IP addresses, and other transaction attributes. My thinking was that more varied transactions would give the model more information to learn from.

The script was useful for simulating traffic. For training a fraud model, though, I ran into a problem.

I was generating random transactions, not necessarily meaningful fraudulent behavior.

Even generating 100,000 transactions wouldn't help much if the fraud labels had no meaningful relationship with the features.

I could keep improving the randomizer, but that wouldn't automatically reproduce realistic patterns of legitimate and fraudulent activity.

That experiment taught me something I hadn't considered carefully enough: generating synthetic data for load testing and generating synthetic data for ML training require different approaches.

I eventually relied on established fraud datasets for model training while retaining the generated transactions for exercising the system.

Why I chose PR-AUC instead of relying on accuracy

Another decision that took more thought than I expected was choosing how to evaluate the models.

I explored accuracy, precision, recall, and ROC-AUC. Each metric answered a useful question, but fraud detection has an important complication: fraudulent transactions are usually a tiny fraction of the data.

Consider the credit-card fraud dataset I used.

It contains 284,807 transactions, with only 492 labeled as fraudulent. That's approximately 0.17%.

A model that predicts every transaction as legitimate would achieve 99.83% accuracy while detecting zero fraud.

That immediately makes accuracy alone an unreliable measure of fraud detection quality.

Precision and recall are more informative.

Precision tells us how many transactions flagged as fraudulent actually are fraudulent. Recall tells us how many of the fraudulent transactions we successfully detected.

The difficulty is balancing them.

If we aggressively flag transactions, recall might improve, but legitimate customers could be caught in the process. If we're too selective, precision might improve while more fraudulent transactions go undetected.

Neither metric tells the complete story independently, especially when the classification threshold changes.

That's why I focused on Precision-Recall AUC (PR-AUC).

PR-AUC summarizes the trade-off between precision and recall across different thresholds. For an imbalanced dataset, it helps us evaluate how well the model identifies the rare positive class without hiding false positives behind the much larger number of legitimate transactions.

I also learned that a PR-AUC score needs context.

In the full credit-card dataset, only about 0.17% of transactions are fraudulent. In IEEE-CIS, the proportion is approximately 3.5%.

For a random ranking, the expected average-precision baseline is approximately the fraud prevalence. That means the reference levels are around 0.0017 and 0.035, respectively, although the exact values depend on the evaluation split.

This matters when interpreting the results.

Why I didn't compare my results directly with Kaggle leaderboards

While working with IEEE-CIS, I noticed that Kaggle competition results often reported much higher-looking scores.

But the original IEEE-CIS competition evaluated submissions using ROC-AUC, while I focused on PR-AUC.

ROC-AUC measures how well a model separates positive and negative cases across thresholds, using the true-positive and false-positive rates.

It's a valid metric, but in highly imbalanced problems, a relatively small false-positive rate can still produce a substantial number of false alerts because legitimate transactions are so numerous.

PR-AUC makes the precision of fraud predictions more visible.

My recorded results were:

recorded results

These scores came from separate datasets and evaluation contexts. They aren't accuracy percentages, and the higher credit-card score doesn't establish that one model is universally better.

For IEEE-CIS, I spent considerable effort on feature engineering, experimenting with models, and hyperparameter tuning. Approximately 0.619 PR-AUC was where those experiments ended.

That was a meaningful result for me, but I wouldn't call it the maximum achievable performance. Different features, training strategies, or additional data could produce stronger results.

I also couldn't directly compare my PR-AUC with a Kaggle ROC-AUC leaderboard score. A fair comparison would require the same evaluation data, metric, and validation protocol.

What changed through these experiments was how I interpreted model performance.

I became more interested in whether the metric reflected the problem I was trying to solve than whether the number looked impressive.

And even then, a good evaluation score couldn't tell me exactly which transactions should be blocked, allowed, or sent for review. That required a separate decision about acceptable fraud risk and the cost of incorrectly flagging legitimate customers.


What building Vigilant changed about how I think about fraud detection

When I started Vigilant, I had considered spending almost two weeks just on model development and experimentation.

I thought training the model would be where most of my effort went.

But the more I worked on the project, the more I realized how much of the challenge existed outside the training process.

Looking back, three lessons stand out.

The first is that the data should influence the model, not the other way around.

I initially tried making different datasets fit a common representation because it seemed convenient. That experience taught me to question whether the features actually carried the information the model needed, rather than focusing only on making the training pipeline work.

The second lesson is that training a model is only one part of building an ML system.

Feature preparation, model selection, inference, evaluation, and handling unexpected inputs all matter. A model might return a perfectly valid numerical prediction, but that doesn't automatically make the prediction reliable or useful.

The third lesson is the one I find most important from a business perspective.

A fraud detection system must protect the business without unnecessarily hurting legitimate customers.

Every incorrect fraud alert has consequences. A genuine customer might be unable to complete a purchase, face an unnecessary review, or lose trust in the service.

At the same time, allowing suspicious transactions without sufficient checks can expose the business and its customers to real financial losses.

Balancing those outcomes is much harder than choosing a classification threshold.

I genuinely enjoyed building Vigilant because it introduced me to problems I hadn't paid much attention to in my earlier ML projects.

It's still a personal engineering project, and I wouldn't compare its scale or maturity with established payment platforms. But exploring these decisions gave me a better appreciation of why fraud detection systems are challenging to design.

I've focused this article on the experiments, mistakes, and lessons that shaped Vigilant. In the next article, I want to explore its architecture and the decisions behind coordinating the different parts of the risk evaluation workflow.

I also plan to cover the ML development lifecycle separately, including data preparation, feature engineering, model experimentation, tuning, and inference.

For now, the biggest lesson I'll carry forward is this:

Building a fraud model is about learning to recognize suspicious patterns. Building a useful fraud detection system is about deciding how much to trust those predictions and what to do with them.


📖 Blog by Naresh B. A.

👨‍💻 Backend & AI Systems Engineer | Distributed Systems · Production ML

🌐 Portfolio: [Naresh B A]

📫 Let's connect on [LinkedIn] | GitHub: [Naresh B A]

Thanks for reading. This is my personal engineering perspective, and I'd genuinely be interested in hearing where you agree or disagree.❤️

Top comments (0)