“This transaction appears regular. However my mannequin thinks it’s fraud and it’s 100% certain.”
That was the second I spotted machine studying isn’t only for scoring metrics. It could actually suppose. It could actually catch what the unique inflexible rule-based techniques from the dataset miss.
On this story, I’ll present you the way I constructed a easy fraud detection mannequin that flagged actual patterns, not simply noise. However extra importantly, I’ll stroll you thru the investigations, the function logic, and the frustrations that made this newbie mission really feel like an actual analyst case research.
HOW I GOT INTO THIS PROJECT
I needed to transcend simply cleansing information or plotting charts from guided tutorials on YouTube. I wanted a mission that felt actual, one thing that mimicked what analysts truly do within the fintech or banking business which I’m coaching myself for.
Then I discovered a cellular cash fraud detection dataset on Kaggle. It had over 6 million transactions and a delicate problem:
Solely 0.1% of them have been fraud.
Good. It wasn’t only a information mission. It was a needle-in-a-haystack state of affairs, precisely what actual fraud analysts cope with daily.
I didn’t wish to simply run a classifier and print metrics. I needed to:
- Perceive what made a transaction look fraudulent
- Create options that mimic actual fraud alerts
- Examine flagged circumstances and clarify why the mannequin thought they have been shady
This mission grew to become extra than simply ML(Machine Studying). It grew to become an expertise.
DATA UNDERSTANDING & FEATURE CRAFTING
The dataset simulated cellular cash transfers with fields like:
- sort: transaction sort (TRANSFER, CASH_OUT, and so forth.)
- quantity: amount of cash moved
- oldbalanceOrg & newbalanceOrig: sender’s stability earlier than and after
- oldbalanceDest & newbalanceDest: receiver’s stability earlier than and after
- isFraud: precise fraud label (floor fact)
- isFlaggedFraud: the system’s rule-based fraud detector
However simply studying these columns wasn’t sufficient. I needed to suppose like a fraud analyst and ask:
- What’s suspicious habits?
- What indicators would possibly a human fraud detector search for?
- Can I train the mannequin to suppose that manner?
That led me to create new options like:
- isOrigEmptied: Was the origin account drained fully?
- balanceDiffRatio: Did the vacation spot stability behave oddly?
- isHighRiskType: Was the transaction a TRANSFER or CASH_OUT?
- isAmountLarge: Was the quantity unusually excessive?
These weren’t simply options. They have been fraud alerts.
Every one was like giving the mannequin a clue, the type a fraud analyst would use in a real-life situation.
Modeling the Thoughts of a Fraud Analyst
I didn’t simply throw information at a mannequin and hope for the perfect.
I constructed a RandomForestClassifier, certain, however the actual work was within the pondering:
- I educated it on options that mimic how actual fraud analysts suppose.
- I prioritized interpretability over fancy scores.
- I needed it to catch fraud that the unique rule-based system within the dataset didn’t detect and clarify why.
The outcome?
The mannequin didn’t simply predict fraud.
It instructed a narrative utilizing numbers, patterns, and pink flags and in some way, it felt like an actual particular person was behind it.
Each prediction felt like…
“This transaction drained the sender’s account… the sort is high-risk… and the receiver’s stability didn’t even transfer? One thing’s off right here.”
And that’s the place the actual enjoyable started: listening to the mannequin’s instincts, one case at a time.
You may actually watch this unfold within the repo notebook
I didn’t simply wish to construct one other machine studying mannequin.
I needed to simulate what actual fraud analysts do in actual life conditions, which is: catch fraud earlier than it slips by way of, and clarify the logic clearly. Not with jargon, however with pattern-based pondering that even a non-tech founder might perceive.
The dataset I used was from Kaggle, a simulation of cellular cash transactions (like M-Pesa, Palmpay, Moniepoint, Kuda, Gray, or OPay) with each legit and fraudulent exercise. It got here with a fundamental flagging system: a column known as isFlaggedFraud that marked apparent fraud utilizing easy guidelines.
However these guidelines weren’t sensible.
They missed the intelligent fraud patterns.
I needed to construct a machine studying mannequin that would:
- Detect suspicious transactions that the unique rule-based system from the dataset didn’t catch
- Clarify why a transaction appeared suspicious in clear language
- Assist non-technical folks perceive what fraud appears like within the information
And as I constructed it, I spotted one thing:
The mannequin wasn’t simply classifying transactions; it was telling a narrative.
It used patterns and pink flags to inform a narrative, one that just about felt human.
Each prediction felt like:
“Right here’s why I feel this transaction smells fishy. Let me stroll you thru it.”
The extra I seemed, the extra I trusted the mannequin’s instincts. And that’s after I knew this wasn’t nearly numbers. It was about translating machine studying into instinct.
I documented the full technical breakdown in this repo if you wish to dive into the engine behind this story.
As soon as the mannequin began making fraud predictions, I didn’t simply have a look at metrics, I adopted the clues.
I handpicked 5 transactions that the mannequin was 100% assured have been fraudulent.
For every one, I placed on my fraud analyst hat and requested:
- Why did the mannequin suppose this was fraud?
- What pink flags have been current?
- Did the unique rule-based system miss it?
- If this occurred in actual life, what would it not seem like?
Then I wrote case-by-case breakdowns in plain English.
Every case wasn’t simply “flagged as fraud.”
It was a narrative: an account drained, a suspicious vacation spot, a high-risk sort.
And essentially the most highly effective half?
Many of the frauds the mannequin caught have been not flagged by the dataset’s built-in rule-based system (isFlaggedFraud).
Meaning the mannequin was catching what conventional guidelines missed and explaining why.
I needed the mannequin to be greater than a black field.
So I made it suppose like a detective, after which I translated its ideas into human human-readable format.
What made the mannequin so sharp wasn’t some fancy algorithm, it was easy human-inspired logic baked into the options.
Listed here are a number of of the MVPs (Most worthy predictors):
- isOrigEmptied → Did the sender’s account drop to zero after the transaction?
- balanceDiffRatio → Did the vacation spot account’s stability not change, even after receiving cash?
- isHighRiskType → Was the transaction a TRANSFER or CASH_OUT? (Most fraud occurs in these two.)
These options didn’t simply increase mannequin accuracy, they instructed tales.
They mimicked how a fraud analyst would suppose:
“If an account is out of the blue drained, or cash goes someplace suspiciously inactive… one thing’s up.”
It was by no means about fancy stats.
It was about observing bizarre habits and coaching the mannequin to note it too.
After coaching the mannequin, I didn’t simply test accuracy and name it a day.
I listened to it.
I picked 5 transactions that the mannequin was 100% assured have been fraud, and I grew to become the fraud detective, asking:
- What patterns did the mannequin see?
- Why did the rule-based system miss it?
- What real-world situation does this resemble?
Every case had its personal twist, however some clues stored exhibiting up:
- The origin account was fully emptied.
- The vacation spot stability didn’t transfer.
- The transaction was excessive threat (TRANSFER or CASH_OUT).
- The system flag mentioned “all clear,” however the mannequin knew higher.
I defined every case the best way I’d break it all the way down to a buddy, no tech speak, simply easy logic anybody might comply with.
It wasn’t nearly catching fraud.
It was about understanding it.
After I first opened the dataset, I gained’t lie, I felt misplaced.
Too many columns, bizarre account names, and no concept what I used to be in search of.
However little by little, function by function, bug by bug, issues began clicking.
I wasn’t simply coaching a mannequin, I used to be coaching my eyes to see like one.
And as soon as it began catching fraud the system missed… I used to be hooked.
This mission confirmed me that even easy fashions can do highly effective issues
If you happen to take the time to suppose like the info.
Let’s collaborate, let’s join
📖 Github
💼ganajoshuadanlami@gmail.com