Siddhant Kumar
Project A21 · Predictive ML

Fraud Detection Model.

Flags suspicious transactions in real time with anomaly detection — where fraud is rare, so the class imbalance and the cost of errors define everything.

Advanced 12–18 hours 24 min read AnomalyFinanceML
Jump to source Bill of materials
Fraud Detection Model — reference build illustration MCU VCC · GND · SIG · NC
Difficulty
Advanced
Build time
12–18 hours
Indicative cost
Software; compute-light to moderate
Platform
CPU/GPU workstation or server
Category
Predictive ML
Last updated
28 July 2026
Contents — 26 sections

Project Overview

Flags suspicious transactions in real time with anomaly detection — where fraud is rare, so the class imbalance and the cost of errors define everything.

Fraud detection — spotting the tiny fraction of transactions that are criminal among the vast majority that are legitimate — is one of the highest-value applications of machine learning, protecting payments, banking and commerce. This project builds a model that flags suspicious transactions in real time. But its defining lesson is not the algorithm; it is that fraud detection is dominated by a single brutal fact — fraud is extremely rare — which reshapes how you build, train and, above all, evaluate the model.

That rarity — a severe class imbalance, often well under 1% of transactions are fraud — breaks the naïve approach. A model that simply predicts "not fraud" for everything achieves >99% accuracy while catching zero fraud, which is why accuracy is a worse-than-useless metric here. The project is really about the techniques that actually work under imbalance: choosing the right metrics (precision, recall, and their trade-off), handling imbalance (resampling, class weighting, anomaly detection that models "normal" and flags deviations), and engineering features that expose fraud patterns.

The value is real-time protection, and the honesty is about the cost of errors, which is asymmetric and business-critical. A false negative (missed fraud) means money lost; a false positive (a legitimate transaction wrongly flagged) means a blocked payment and an angry customer — and there are far more legitimate transactions, so even a low false-positive rate produces a flood of false alarms. So the whole game is tuning the precision/recall trade-off to the business's costs, not chasing accuracy. It is also honest that fraud adapts (an adversarial, drifting target requiring constant retraining), that decisions affecting people need care and often human review, and that labels are noisy. Built with imbalance-aware methods and cost-driven evaluation, it is both a genuinely valuable system and the definitive lesson in machine learning where the classes are rare and the errors are not equal.

A schematic of a feed-forward artificial neural network
A fraud detection model flags the rare criminal transactions among a flood of legitimate ones in real time. Photograph sourced from Wikimedia Commons — Artificial neural network.svg. Reused under the licence stated on that page; please check it before republishing.

What this project does

  • Flags suspicious transactions in real time
  • Handles severe class imbalance (fraud is rare)
  • Uses anomaly detection / imbalance-aware methods
  • Evaluates with precision/recall, not accuracy
  • Tunes the precision/recall trade-off to error costs
  • Engineers features that expose fraud patterns
  • Supports human review of flagged cases

Real-World Applications

SettingHow it is used
Payment / card fraudReal-time transaction risk scoring.
Banking / account fraudDetecting anomalous account activity.
E-commerceFlagging suspicious orders.
Imbalanced-ML learningRare-event detection done right.

Deployment contexts where a build of this kind earns its keep.

Features & Capabilities

  • Imbalanced-classification / anomaly detection
  • Precision/recall (not accuracy) evaluation
  • Resampling / class weighting
  • Cost-aware threshold tuning
  • Real-time scoring
  • Retraining for adaptive fraud
  • Honest about false-positive floods and adversarial drift

Difficulty, Time & Required Skills

AttributeValue
Difficulty levelAdvanced
Estimated completion time12–18 hours
Indicative build costSoftware; compute-light to moderate
Primary disciplinePredictive ML
Reference platformCPU/GPU workstation or server

Skills you should have (or will pick up)

  • Imbalanced classification and anomaly detection
  • Precision/recall and cost-aware evaluation
  • Resampling / class weighting
  • Threshold tuning to business costs
  • Handling adversarial drift and retraining

Bill of Materials

Every part below is commonly available from Indian and international hobby-electronics suppliers. Prices are indicative 2026 retail figures in Indian rupees and will drift — treat them as a budgeting guide, not a quotation.

ComponentKey specificationQtyApprox. cost
ComputeCPU/GPU for training and real-time scoring1
ML librariesImbalanced-learning / anomaly detection1
Transaction data
Fraud is rare
Labelled transactions (very imbalanced)1
Review workflow
Decisions affect people
Human review of flagged cases1

Estimated total: ₹0, excluding tools, shipping and consumables.

Tools and consumables

  • Soldering iron (temperature controlled, 350 °C) with 0.8 mm 60/40 or lead-free solder
  • Digital multimeter — continuity, DC volts and current ranges
  • Wire strippers, flush cutters and a small set of precision screwdrivers
  • Heat-shrink tubing and a heat gun (or a lighter, carefully)
  • A laptop with a USB port and the toolchain listed above

Hardware Specifications

This is a pure-software ML system — no electronic hardware to specify. The "platform" is a computer: a CPU handles most models and real-time scoring; a GPU helps for large-scale training.

Memory scales with transaction volume and features; a real deployment adds a low-latency scoring service, a labelled-data pipeline, and a human-review queue. Everything else is the software stack, models and libraries below.

Software Requirements & Development Environment

Reference toolchain: Python 3.11 + ML (imbalanced classification). Anything newer normally works; anything older may lack the board definitions used here.

  • Install the Arduino IDE 2.3.x (or PlatformIO if you prefer a real editor and dependency locking).
  • Add https://espressif.github.io/arduino-esp32/package_esp32_index.json under File → Preferences → Additional Board Manager URLs, then install esp32 from the Boards Manager.
  • Set the correct port under Tools → Port. On Linux add yourself to the dialout group: sudo usermod -aG dialout $USER and log out and back in.
  • Open the Serial Monitor at 115200 baud — every sketch here logs its state there.
  • Keep File → Preferences → Show verbose output during: compilation switched on while you are debugging build errors.

Required libraries

LibraryWhy it is neededInstall
Python 3.11+Runtime for the analysis, training and service code.sudo apt install python3 python3-venv python3-pip
scikit-learn 1.5+Classical models, preprocessing pipelines and evaluation metrics.pip install scikit-learn
pandas 2.2+Tabular data loading, cleaning and time-series resampling.pip install pandas
NumPy 1.26+Vectorised array maths underpinning every other library here.pip install numpy

Block Diagram

The block diagram shows the functional decomposition of the system — what senses, what decides, what acts, and where the data ends up.

Fraud Detection Model — system block diagramFunctional block diagram of the Fraud Detection Model system. TransactionFeaturessignalsScoreModelimbalance-awareFraud probriskDecideThresholdcost-tunedPrecision/recalltrade-offActFlagreview/blockRetrainadaptsrightrightnone
Fraud Detection Model — system block diagram

Circuit Diagram & Wiring

The "wiring" is the detection data flow — a transaction is scored in real time by an imbalance-aware model; a cost-tuned threshold decides whether to flag it for action or review.

Fraud Detection Model — wiring schematicConnection schematic showing which controller pin drives each peripheral. Sensors / InputsControllerActuators / OutputsCPU/GPU workstationor server3.3 V logic / 5 V USBTransactionRisk signalsModelFraud probabilityThreshold (cost-tuned)Flag / allowReview / actionBlock/confirm
Fraud Detection Model — wiring schematic
PeripheralPeripheral pinController pinSignal
TransactionfeaturesRisk signals
ModelscoreFraud probability
Threshold (cost-tuned)decideFlag / allow
Review / actionhumanBlock/confirm

Wire one row at a time and tick it off — most "it does not work" reports trace back to a single swapped pair.

Wiring explanation

  • Engineer features that expose fraud patterns (amount, velocity, location, history).
  • Score each transaction with an imbalance-aware / anomaly-detection model.
  • Apply a threshold tuned to error costs (not accuracy).
  • Flag suspicious transactions for action and/or human review.
  • Retrain regularly — fraud adapts.
Racks of servers in a data centre
Fraud is rare, so accuracy is meaningless — precision, recall and a cost-tuned threshold define the model. Photograph sourced from Wikimedia Commons — Datacenter servers.jpg. Reused under the licence stated on that page; please check it before republishing.

System Architecture

Read the stack from the bottom up: physical hardware, the firmware that drives it, the transport that moves data off the device, and the software a human actually looks at.

Fraud Detection Model — architecture stackLayered architecture from hardware to user interface. Hardware layerESP32 DevKit V1 (ESP-WROOM-32) · sensors and actuatorsDriver layerpython · sklearn · pandas · numpyApplication logicsampling loop · filtering · thresholds · state machinePresentation layerlocal display · serial console · logged output
Fraud Detection Model — architecture stack

Working Principle

Fraud detection looks like a classification problem — label each transaction fraud or not — but it is dominated by one property that changes everything: fraud is extremely rare. In real data, the fraudulent fraction is often well under 1%, sometimes a fraction of that. This severe class imbalance is not a detail to handle at the end; it is the central fact that dictates how you train, what algorithms work, and — most importantly — how you must measure the model. Internalising that is the whole point of the project.

The first casualty of imbalance is the metric everyone reaches for: accuracy is worthless here, actively misleading. A model that predicts "not fraud" for every transaction is >99% accurate and catches zero fraud — a perfect illustration of why accuracy on imbalanced data is meaningless. The right metrics are precision (of the transactions we flagged, how many were truly fraud?) and recall (of all the fraud, how much did we catch?), along with their trade-off (the precision-recall curve). These directly express what the business cares about, and they are the only honest way to judge a rare-event detector.

The techniques that work under imbalance follow from taking it seriously. You can resample (oversample fraud or undersample legitimate transactions to rebalance training), use class weighting (penalise missing the rare class more heavily), or frame it as anomaly detection — model what "normal" transactions look like and flag those that deviate, which is natural when fraud is rare and varied. Alongside, feature engineering exposes fraud signatures: transaction amount and its unusualness for this customer, velocity (many transactions in a short time), location/device anomalies, and deviation from the customer's history. Good features often matter more than the choice of model.

The deepest lesson, and where the honesty lives, is the asymmetric and unequal cost of errors. A false negative — missed fraud — costs money directly. A false positive — a legitimate transaction wrongly declined — costs a blocked payment, a frustrated customer, and support burden. These costs are different, and crucially there are vastly more legitimate transactions than fraud, so even a low false-positive rate produces a large absolute number of false alarms that can swamp a review team and anger real customers. The entire operational challenge is therefore tuning the decision threshold to the business's cost trade-off — how much recall (caught fraud) you buy at the price of how much precision (false alarms) — not maximising some single accuracy number. Three further honest realities complete the picture: fraud is adversarial and drifting (fraudsters actively adapt to evade detection, so the target moves and models must be retrained continually); decisions affect real people (a wrongful decline or accusation has consequences), so serious deployments keep human review in the loop and watch for bias; and labels are noisy (some fraud is never discovered, some flags are wrong). Built with imbalance-aware methods, precision/recall-and-cost-driven evaluation, and a threshold tuned to real error costs, the model delivers genuine value — real-time protection — while teaching the essential discipline of machine learning when the thing you're hunting is rare and the mistakes are not created equal.

The maths behind it

Why accuracy fails

plainWhy accuracy fails
fraud ≈ 0.2% of transactions
"predict not-fraud always" → 99.8% accuracy, 0 fraud caught

→ ACCURACY IS MEANINGLESS on imbalanced data.

The right metrics

plainThe right metrics
precision = TP / (TP + FP)   # of flags, how many are real fraud
recall    = TP / (TP + FN)   # of all fraud, how much we catch

Tune the precision/recall trade-off (PR curve) to the business.

Cost-tuned threshold (the real game)

plainCost-tuned threshold (the real game)
flag if fraud_score ≥ threshold

false negative (miss)  → money lost
false positive (false alarm) → blocked payment + angry customer
  and legit ≫ fraud → low FP RATE still = MANY false alarms

choose threshold by expected COST, not accuracy.

Program Flowchart

The firmware is a single cooperative loop. Nothing blocks for long, so networking, sensing and the user interface all stay responsive.

Fraud Detection Model — firmware flowchartControl flow through the main program loop. Transaction arrivesEngineer features / scoreScore above cost-tunedthreshold?Flag (review/block)AllowFlag (review/block)AllowHuman review where neededFeed back + retrain (fraudadapts)
Fraud Detection Model — firmware flowchart

Assembly Instructions

Build on a breadboard first and only commit to solder once the whole system has run for an hour without a fault.

  1. Engineer features and handle imbalance

    Engineer fraud-relevant features and handle the severe imbalance (resampling, class weighting, or anomaly detection).

  2. Score and tune the threshold to cost

    Score transactions and set the decision threshold by the business cost trade-off between missed fraud and false alarms.

  3. Review, feed back and retrain

    Route flags to human review where needed, and retrain regularly because fraud adapts.

Step-by-Step Implementation Guide

Work through these in order. Each step ends in something you can observe, so a failure is always localised to the step you just finished.

  1. Score and decide with a cost-tuned threshold

    Score each transaction's fraud probability and flag it against a threshold tuned to error costs, routing to review.

    pythonfraud.py
    def score(txn, model, features):
        return float(model.predict_proba([features(txn)])[0][1])   # fraud probability
    
    def decide(txn, model, features, threshold):
        # threshold TUNED TO COST (precision/recall), NOT accuracy
        p = score(txn, model, features)
        if p >= threshold:
            return {"action": "flag", "score": round(p, 3), "route": "review"}  # people-affecting
        return {"action": "allow", "score": round(p, 3)}
    return float(model.predict_proba([features(txn)])[0][1]) # fraud probabilityThe model outputs a fraud probability from engineered features — a score, not a hard label, so the threshold can be tuned.
    # threshold TUNED TO COST (precision/recall), NOT accuracyThe decision threshold is set by the business cost trade-off between missed fraud and false alarms — the real operational lever.
    return {"action": "flag", "score": round(p, 3), "route": "review"} # people-affectingFlags route to human review because these decisions affect real people — a wrongful decline has consequences.
  2. Manage false-alarm volume and drift

    Tune to keep false-alarm volume manageable for the review team, and retrain regularly as fraud patterns adapt.

Complete Source Code

The listing below is complete and compiles as written — there are no elided sections. Read the annotations under each block before you upload it.

pythonfraud_detection.py
#!/usr/bin/env python3
"""
Fraud Detection Model

Flags rare fraudulent transactions in real time. The defining fact is
IMBALANCE (fraud is very rare), which makes ACCURACY MEANINGLESS. Use
precision/recall, handle imbalance (resample/weight/anomaly detection),
and TUNE THE THRESHOLD TO ERROR COSTS. Fraud adapts -> retrain; decisions
affect people -> human review.
"""
class FraudDetector:
    def __init__(self, model, features, threshold):
        self.model = model; self.features = features
        self.threshold = threshold          # cost-tuned, NOT accuracy-tuned

    def score(self, txn):
        return float(self.model.predict_proba([self.features(txn)])[0][1])

    def decide(self, txn):
        p = self.score(txn)
        if p >= self.threshold:
            return {"action": "flag", "score": round(p, 3), "route": "human_review"}
        return {"action": "allow", "score": round(p, 3)}

    @staticmethod
    def evaluate(y_true, y_prob, threshold):
        pred = [1 if p >= threshold else 0 for p in y_prob]
        tp = sum(t and p for t, p in zip(y_true, pred))
        fp = sum((not t) and p for t, p in zip(y_true, pred))
        fn = sum(t and (not p) for t, p in zip(y_true, pred))
        return {                              # NOT accuracy
            "precision": tp / (tp + fp + 1e-9),   # false-alarm control
            "recall":    tp / (tp + fn + 1e-9),   # fraud caught
            "false_alarms_abs": fp,               # legit >> fraud -> watch this
        }

if __name__ == "__main__":
    det = FraudDetector(trained_model, make_features, threshold=0.7)
    print(FraudDetector.evaluate(Y_TEST, PROBS, threshold=0.7))
    # Tune threshold to cost; retrain as fraud drifts; keep humans in the loop.
self.threshold = threshold # cost-tuned, NOT accuracy-tunedThe threshold is the core control, set by error costs rather than accuracy — the operational heart of fraud detection.
return {"action": "flag", "score": round(p, 3), "route": "human_review"}Flagged transactions go to human review, because these are people-affecting decisions that should not be fully automated.
return { # NOT accuracyEvaluation deliberately reports precision/recall and false-alarm counts, never accuracy, which is meaningless under imbalance.
"false_alarms_abs": fp, # legit >> fraud -> watch thisThe absolute false-alarm count is tracked because, with legit transactions vastly outnumbering fraud, even a low rate floods the review team.

Configuration & Calibration

Configuration steps

  • Configure fraud-relevant features and imbalance handling.
  • Configure the model / anomaly detector.
  • Configure the decision threshold to error costs (precision/recall).
  • Configure review routing and retraining cadence.

Calibration procedure

An uncalibrated sensor produces confident, precise, wrong numbers. Do this once per physical unit and record the constants.

  1. Metrics

    Evaluate with precision/recall and PR curves; never accuracy.

  2. Threshold

    Tune to the business cost trade-off and the false-alarm volume review can handle.

  3. Drift

    Monitor for adversarial drift; retrain regularly.

Dataset, Model & Training

Dataset

Highly imbalanced labelled transactions (fraud ≪ legitimate). Labels are noisy (undiscovered fraud, wrong flags).

Feature engineering (amount, velocity, history deviation) often matters more than model choice.

DatasetSizeLicenceUse here
Labelled transactionsLarge, ≪1% fraudSensitive/regulatedTrain/evaluate (imbalanced)
Engineered featuresDerivedAmount/velocity/history signals
Held-out (time-aware) testFuture periodHonest, drift-aware evaluation
Review outcomesGrowingSensitiveFeedback / retraining labels

Data preprocessing

  • Engineer fraud-relevant features (amount, velocity, location/device, history deviation).
  • Handle imbalance: resampling, class weighting, or anomaly-detection framing.
  • Split time-aware (fraud drifts); avoid leakage.
Fraud Detection Model — ML pipelineFrom raw data through training to deployed inference. 1Transactionfeatures2Imbalance handlingresample/weight3Model / anomalyscore4Thresholdcost-tuned5Flag + reviewact
Fraud Detection Model — ML pipeline
Layer / stageShape or configurationPurpose
Feature engineeringamount/velocity/historyExpose fraud patterns
Imbalance handlingresample / class weightLearn the rare class
Modelclassifier / anomaly detectorScore fraud risk
Thresholdcost-tuned (PR trade-off)Business-optimal flags
RetrainingongoingAdapt to drifting fraud

Hyperparameters

HyperparameterValueWhy
Class weight / samplingtunedLearn rare fraud
Decision thresholdcost-tunedPrecision vs recall
Feature setrichOften > model choice
Retrain cadencefrequentAdversarial drift

Training process

  • Handle imbalance (resample/weight or anomaly detection); engineer strong features.
  • Evaluate with precision/recall and PR curves — never accuracy.
  • Split time-aware; plan continual retraining as fraud adapts.

Evaluation, Metrics & Deployment

The honest metrics are precision, recall and their trade-off at a cost-tuned threshold — accuracy is meaningless under this imbalance.

MetricValueWhat it tells you
Precisioncost-tunedFalse-alarm control
Recallcost-tunedFraud caught
PR-AUCprimaryImbalance-appropriate
AccuracyIGNOREMisleading here

Figures from the reference training run described above — reproduce them before trusting your own changes.

Precision vs recall trade-offCatching more fraud (recall) costs precision (more false alarms); the threshold is tuned to business error costs, not accuracy (illustrative). High-precision setting92 %Balanced78 %High-recall setting60 %Accuracy (misleading)99 %
Precision vs recall trade-off

Inference example

pythonfraud.py
def score(transaction, model, features):
    x = features(transaction)                # amount/velocity/history deviation
    return float(model.predict_proba([x])[0][1])   # fraud probability

def decide(transaction, model, features, threshold):
    # threshold is TUNED TO COST, not accuracy.
    p = score(transaction, model, features)
    if p >= threshold:
        return {"action": "flag", "fraud_score": round(p, 3),
                "route": "human_review"}     # decisions affect people
    return {"action": "allow", "fraud_score": round(p, 3)}
    # Legit >> fraud: even a low FP RATE = many false alarms. Retrain often.

Testing Procedure & Expected Output

Test from the bottom up. Confirm power, then each sensor in isolation, then the integrated loop — the first failing step tells you exactly where to look.

TestWhat you should see
Baseline "never fraud">99% accuracy, 0 recall — shows accuracy is useless
Evaluate precision/recallMeaningful assessment
Lower the thresholdMore recall, more false alarms
Count absolute false alarmsLarge even at low FP rate (legit ≫ fraud)
Simulate fraud driftPerformance decays — retrain
Flagged caseRouted to human review

Bench-test checklist. If a row fails, stop and fix it before moving on.

Expected output

Real-time fraud flags with precision/recall-based evaluation and cost-tuned thresholds, routed to review.

jsonfraud-eval.json
{
  "precision": 0.82,
  "recall": 0.64,
  "false_alarms_abs": 1240,
  "accuracy": "ignored (meaningless here)",
  "threshold": 0.70,
  "note": "tune to cost; legit >> fraud floods false alarms; fraud adapts"
}

An honest evaluation: precision and recall (not accuracy), with the absolute false-alarm count front and centre — because even a good rate produces many false alarms when legitimate transactions vastly outnumber fraud.

A Grafana time-series dashboard
Legitimate transactions vastly outnumber fraud, so even a low false-positive rate floods review with false alarms. Photograph sourced from Wikimedia Commons — Grafana dashboard.png. Reused under the licence stated on that page; please check it before republishing.

Troubleshooting: Common Errors & Fixes

High accuracy, catches no fraud

Likely cause. Imbalance + wrong metric

Fix. Ignore accuracy; use precision/recall; handle imbalance

Too many false alarms

Likely cause. Threshold too low / weak features

Fix. Raise threshold to cost; better features

Misses too much fraud

Likely cause. Threshold too high / imbalance

Fix. Lower threshold; resample/weight; anomaly detection

Degrades over time

Likely cause. Adversarial drift

Fix. Retrain regularly; monitor drift

Unfair/biased decisions

Likely cause. Data/proxies

Fix. Audit fairness; human review; mitigate bias

Leakage inflates results

Likely cause. Non-time-aware split

Fix. Time-aware split; avoid future info

The sketch will not upload — "Failed to connect" or "avrdude: stk500_recv()"

Likely cause. The bootloader is not being reached: wrong port, wrong board, a serial monitor holding the port open, or a USB cable that only carries power.

Fix. Close every serial monitor, confirm Tools → Board and Port, and swap to a known data-capable USB cable. On an ESP32 hold BOOT while the IDE prints "Connecting…", then release. If a peripheral is wired to the UART pins (GPIO 1/3 on ESP32, D0/D1 on Uno) unplug it — it fights the programmer.

The board resets in a loop, or the serial monitor prints "Brownout detector was triggered"

Likely cause. The supply cannot deliver peak current. Wi-Fi transmit bursts, relay coils and servos all pull far more than their average draw.

Fix. Power peripherals from a separate regulated supply with a common ground rather than from the board 5 V pin. Add a 470–1000 µF electrolytic capacitor across the supply near the load, and use a real power adapter rather than a laptop USB port.

Serial monitor shows garbage characters

Likely cause. Baud rate mismatch between Serial.begin() and the monitor, or a floating/shared UART line.

Fix. Set the monitor to 115200 to match the sketch. If it still garbles, the crystal or the USB bridge is being confused by noise — shorten the cable and keep motor wiring away from the USB lead.

Performance Optimisation

  • Never use accuracy — evaluate precision/recall and PR curves.
  • Handle imbalance (resample/weight/anomaly detection).
  • Tune the threshold to error costs and false-alarm volume.
  • Retrain regularly for adversarial drift; engineer strong features.
  • Replace every delay() with a millis() comparison — blocking delays are the single most common cause of dropped readings.
  • Sample sensors on a fixed cadence and publish on a slower one; you almost never need to transmit at the sampling rate.
  • Move networking into its own FreeRTOS task so a slow DNS lookup cannot stall the control loop.
  • Use uint8_t / uint16_t where the range allows; on an 8-bit AVR a 32-bit add costs four times as much.
  • Profile before optimising — print micros() deltas around each stage and fix the slowest one first.

Safety Precautions

  • Decisions affect people — keep human review for flagged cases; a wrongful decline has consequences.
  • Watch for and mitigate bias; audit fairness of decisions.
  • Transaction data is sensitive/regulated — secure and handle it lawfully.
  • Fraud adapts — do not treat a static model as reliable; monitor and retrain.
  • Wear eye protection when soldering or cutting, and solder in a ventilated space — rosin flux fumes are a respiratory irritant.
  • Power the circuit through a bench supply with a current limit while you are testing. A 300 mA limit turns a wiring mistake into a beep instead of a dead board.
  • Disconnect power before changing any wiring. Hot-plugging a sensor onto a live bus is the fastest way to lose a controller.

Maintenance

  • Retrain frequently as fraud patterns drift.
  • Monitor precision/recall and false-alarm volume in production.
  • Refresh features and feedback labels from review outcomes.
  • Audit fairness and data handling.
  • Re-check every screw terminal and header after the first week — thermal cycling loosens connections that felt tight on day one.
  • Recalibrate at the interval given in the calibration section, and keep the constants in a text file next to the firmware — not only in flash.
  • Keep a short logbook of firmware versions and what changed. Six months later you will not remember why that constant is 1.083.

Future Improvements & Upgrades

A working v1 is a platform, not a finish line. These are the upgrades that add the most capability for the least rework.

  • Add graph/network features (fraud rings).
  • Add real-time streaming and adaptive thresholds.
  • Add explainability for review and appeals.
  • Add active learning from review outcomes.
  • Design a proper PCB. Once the breadboard version has run for a month, moving to a two-layer board removes the intermittent-contact failures that dominate prototype faults.
  • Add connectivity — an ESP32 and an MQTT publish turn a local gadget into something you can graph, alert on and analyse over months.
  • Add persistent local storage (microSD or the on-chip flash) so a network outage does not create a hole in your data.
  • Move configuration out of the source: a captive-portal setup page or a JSON config file makes the build reusable without a recompile.
  • Add a battery and solar option so the unit survives a power cut and can be sited away from a socket.
  • Write a small test harness that feeds synthetic sensor values through the decision logic, so you can validate thresholds without physically triggering the event.

Frequently Asked Questions

Why is accuracy the wrong metric?

Because fraud is extremely rare. A model that predicts "not fraud" for everything is over 99% accurate yet catches zero fraud. Under severe imbalance, accuracy is actively misleading — you must use precision (are flags real?) and recall (is fraud caught?) instead.

How do you handle the imbalance?

By taking it seriously: resampling (over/under-sampling), class weighting (penalise missing the rare class), or framing it as anomaly detection (model "normal", flag deviations) — combined with features that expose fraud patterns, which often matter more than the model.

Why do false positives matter so much?

Because legitimate transactions vastly outnumber fraud, so even a low false-positive rate produces a large absolute number of false alarms — blocked payments, angry customers, and a swamped review team. Managing false-alarm volume is central.

What decides the threshold?

The business cost trade-off: how much fraud you catch (recall) versus how many false alarms you cause (precision), tuned to the actual costs of a missed fraud versus a wrongful decline — not to any accuracy figure.

Why must it be retrained?

Because fraud is adversarial — fraudsters actively adapt to evade detection — so the target drifts and a static model decays. Continual retraining and drift monitoring are required, and serious deployments keep humans in the loop.

References & Learning Resources

These are the primary sources worth reading in full. Manufacturer datasheets always outrank forum posts when the two disagree.

  1. Fraud detectionReference
  2. Class imbalance problemReference
  3. Precision and recallReference
  4. Anomaly detectionReference
  5. Accuracy paradoxReference