Built to order

Credit Card Fraud Detection using XGBoost

This project builds an XGBoost classifier that scores credit-card transactions for fraud in milliseconds, trained on the public ULB dataset of 284,807 European card transactions with only 0.172% frauds. It ships with the complete training notebook covering imbalance handling (class weights, AUPRC tuning), threshold selection on the precision–recall curve, and a web demo where a live transaction stream is scored with per-transaction risk evidence. Suitable for B.E./B.Tech final-year projects in Computer Science, IT and AI & Machine Learning.

Credit Card Fraud Detection using XGBoost — project thumbnail preview
More project photos (2)

The problem

Credit-card fraud is a textbook imbalanced problem: 492 frauds hide among 284,807 legitimate transactions, so a model that predicts "legitimate" every time scores 99.83% accuracy and catches nothing. Most student builds report that accuracy and stop. This project does the real work: an XGBoost classifier with class-weighted loss, tuned on area under the precision–recall curve, with the operating threshold chosen explicitly from the precision–recall trade-off — because every false positive blocks a genuine customer. The demo streams transactions, scores each in milliseconds, and breaks down the top contributing anonymized features (V14, V17, V12 — the same components fraud literature flags) for every decision. Built with standard tools (Python, XGBoost, scikit-learn), the full methodology is viva-ready.

How it works

  1. The ULB credit-card dataset (284,807 transactions, 30 features: Time, Amount, V1–V28 PCA components) is loaded with a stratified train/test split.
  2. Features are scaled; the extreme imbalance is handled with XGBoost class weights instead of naive oversampling.
  3. The model is trained with early stopping, tuned by cross-validated AUPRC — never by accuracy.
  4. The precision–recall curve on validation data sets the operating threshold: 0.91 recall at 0.94 precision is the design target.
  5. Held-out transactions are scored once: confusion matrix, PR curve and per-threshold tables go into the report.
  6. The web demo streams transactions through the saved model, rendering risk scores with feature-level evidence per decision.

Tech stack:

  • Python 3, XGBoost
  • scikit-learn (metrics, splits)
  • NumPy, pandas, Matplotlib
  • Jupyter Notebook (training & evaluation)
  • HTML5 canvas + JavaScript (screening demo)
  • ULB credit-card fraud dataset (Kaggle)

Dataset & model details

  • Dataset: Kaggle "Credit Card Fraud Detection" (Machine Learning Group, ULB Brussels) — 284,807 transactions over 2 days in Sep 2013, 492 frauds (0.172%); features Time, Amount, V1–V28 (PCA-anonymized for confidentiality).
  • Task: Binary classification under extreme imbalance; input = 30 features, output = fraud probability in [0, 1].
  • Model: XGBoost binary classifier, max_depth 6, scale_pos_weight ≈ 577, early stopping; threshold selected from the validation precision–recall curve.
  • Metrics: AUPRC, recall@precision, F1 — 0.91 recall / 0.94 precision is the design target for the built-to-order training run, stated honestly and never claimed as measured.
Parameter Value
Transactions 284,807 (492 frauds, 0.172%)
Features 30 (Time, Amount, V1–V28)
Recall (fraud) 0.91 (design target, not a measured claim)
Precision 0.94 (design target, not a measured claim)
Scoring latency Approximately 9 ms per transaction on CPU (expected)
Demo Single-file web app, runs offline after download

Project features

  • [Imbalance-aware XGBoost] Class-weighted gradient boosting (scale_pos_weight ≈ 577) so the 0.172% fraud minority is actually learned, not ignored.
  • [AUPRC-tuned, not accuracy-tuned] Model selection on area under the precision–recall curve — the correct metric when the positive class is this rare.
  • [Threshold from the PR curve] The operating point is chosen explicitly to trade fraud recall against false alarms, with the trade-off documented.
  • [Live screening demo] A transaction stream scored in real time; click any transaction for its risk gauge and top contributing features.
  • [Risk evidence per transaction] Each score decomposes into the driving V-components, amount and time signals — auditable, not a black box.
  • [Fraud-pattern visualizations] PCA-space scatter and hour-of-day fraud distribution showing where frauds separate from legitimate traffic.
  • [Retraining playbook] The report documents how to retrain on fresh labels as fraud patterns drift — the operational reality of this task.

What is included

  • Complete training & evaluation Jupyter notebook (imbalance handling, PR tuning)
  • Tuned XGBoost model file with inference code
  • Live transaction-screening web demo with risk evidence
  • Confusion matrix, PR-curve analysis and threshold tables
  • Project report PDF (imbalance theory, methodology, honest evaluation)
  • PPT presentation for final review
  • Viva Q&A preparation document (AUPRC vs accuracy, class weights, thresholding, drift)

Limitations & prerequisites

  • 0.91 recall / 0.94 precision are design targets for the training run, stated honestly — the report documents the actual achieved figures after training.
  • Features V1–V28 are PCA-anonymized, so the model learns statistical shape, not human-readable transaction semantics.
  • Fraud tactics drift over time; a model trained on 2013 data needs scheduled retraining on fresh labels — the report covers this explicitly.
  • The demo stream is illustrative; connecting to a real payment gateway is out of scope.
  • Blocking decisions carry business cost — the threshold analysis exists precisely because false positives block real customers.

Frequently Asked Questions

Which dataset is used?

The ULB credit-card fraud dataset on Kaggle — 284,807 real European card transactions with 492 confirmed frauds. It is the standard public benchmark for this task; features are PCA-anonymized to protect cardholder privacy.

Why not just report accuracy?

Because 99.83% accuracy is achieved by predicting "legitimate" always and catching zero frauds. The project tunes and reports AUPRC, recall and precision instead — the metrics that actually measure fraud-catching ability.

How does the model handle only 0.172% frauds?

XGBoost class weights make each fraud ~577× more important in the loss, so the minority class is learned rather than ignored. The notebook compares this against resampling alternatives.

What does the risk evidence show?

For each transaction, the top contributing features (e.g. V14 deep in the fraud tail, night-time hour, amount z-score) — so a fraud analyst can audit why a transaction was blocked.

Will it work on new fraud tricks?

Only after retraining on fresh labels — fraud drifts, and the report's retraining playbook covers exactly how a production team keeps the model current.

Is this project suitable for a final-year project?

Yes — for Computer Science, IT and AI/ML programs. It demonstrates the single most important lesson in applied ML: choosing the right metric for an imbalanced problem. Suitable for B.E./B.Tech final-year projects in Computer Science, IT and AI & Machine Learning.

Components & software requirements
  • Python 3, XGBoost
  • scikit-learn (metrics, splits)
  • NumPy, pandas, Matplotlib
  • Jupyter Notebook (training & evaluation)
  • HTML5 canvas + JavaScript (screening demo)
  • ULB credit-card fraud dataset (Kaggle)

Dataset & model details

  • Dataset: Kaggle "Credit Card Fraud Detection" (Machine Learning Group, ULB Brussels) — 284,807 transactions over 2 days in Sep 2013, 492 frauds (0.172%); features Time, Amount, V1–V28 (PCA-anonymized for confidentiality).
  • Task: Binary classification under extreme imbalance; input = 30 features, output = fraud probability in [0, 1].
  • Model: XGBoost binary classifier, max_depth 6, scale_pos_weight ≈ 577, early stopping; threshold selected from the validation precision–recall curve.
  • Metrics: AUPRC, recall@precision, F1 — 0.91 recall / 0.94 precision is the design target for the built-to-order training run, stated honestly and never claimed as measured.
Delivery information

Built-to-order project. Delivery timeline is shared after order confirmation based on current queue.

Support terms

Complete documentation, setup guide, and viva preparation included. Support for setup and explanation provided.

Download abstract (PDF)

Related guides

All guides
Illustration of object tracking showing video frames with bounding boxes and persistent ID labels following people and vehicles, comparing motion prediction and appearance matching.B.E./B.Tech Computer Science and Electronics students building video analytics projects — people counting, vehicle tracking, sports analysis — who have detection working and need

Object Tracking: DeepSORT and ByteTrack Explained

Detection finds objects per frame; tracking keeps their identities across frames. This guide explains tracking-by-detection, Kalman motion models, DeepSORT's appearance embeddings vs ByteTrack's low-confidence box recovery, tracking metrics (HOTA, IDF1, ID switches), and the tuning parameters that determine real-world quality.

Read guide
Illustration of image segmentation showing U-Net's U-shaped encoder-decoder with skip connections producing pixel masks, alongside Mask R-CNN detecting instances with masks.B.E./B.Tech Computer Science and AI/ML students moving from image classification or detection to pixel-level understanding — medical imaging, defect detection, autonomous driving

Image Segmentation: U-Net and Mask R-CNN

When projects need pixel-level answers, segmentation delivers. This guide explains semantic vs instance vs panoptic segmentation, U-Net's encoder-decoder with skip connections, Mask R-CNN's parallel mask head, Dice and IoU evaluation, paired augmentation, and how to choose the right architecture for your data and question.

Read guide
Illustration of Whisper speech-to-text showing sound waves flowing into a neural network and emerging as transcribed text with timestamps and speaker labels.B.E./B.Tech Computer Science and AI/ML students adding speech-to-text to projects — voice assistants, meeting transcription, accessibility tools

Whisper for Speech-to-Text in Student Projects

Whisper transcribes speech in dozens of languages with no training required. This guide covers how it works, choosing among model sizes, running it locally with faster-whisper, handling hour-long audio, timestamps and speaker diarization, multilingual quirks, and honest evaluation with word error rate.

Read guide
Get a quotation