SAMANTUS Python for Data Analytics — Complete Training Manual CAPSTONE PROJECT 15
← Back to Course Index

Fraud Detection Analysis


On This Page

Capstone Project 15: Fraud Detection Analysis


C15.1  Project Overview

This final capstone project analyzes transaction data to identify patterns associated with fraudulent activity — a foundational, rule-based approach to fraud analytics before moving into machine learning.

C15.2  Business Problem

A payments company wants to understand what typically distinguishes fraudulent transactions from normal ones — by amount and by time of day — to build simple early-warning flagging rules.

C15.3  Dataset Description

ColumnDescription
transaction_idUnique transaction identifier
amountTransaction amount (Rs.)
hourHour of day the transaction occurred (0-23)
labelNormal or Fraud (based on historical review)

Sample scope: 500 transactions, including 20 confirmed fraud cases.

C15.4  Objectives


C15.5  Step-by-Step Solution

C15.6  Complete Python Code

► fraud_detection.py
import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv("transactions.csv")

avg_by_label = df.groupby('label')['amount'].mean()
print("Average Amount - Normal vs Fraud:\n", avg_by_label.round(2))

fraud_rate_by_hour = df.groupby('hour')['label'].apply(lambda x: (x=='Fraud').mean()*100)
print("Fraud Rate % by Hour:\n", fraud_rate_by_hour.round(1))

# Simple rule-based flag
threshold = df[df['label']=='Fraud']['amount'].quantile(0.25)
df['flagged'] = df['amount'] > threshold

accuracy = (df['flagged'] == (df['label']=='Fraud')).mean() * 100
print(f"Simple Rule Accuracy: {accuracy:.1f}%")

C15.7  Expected Output

Output
Average Amount - Normal vs Fraud:
Normal   1,480
Fraud     8,650

C15.8  Visualizations

Figure C15.1 — Transaction amount comparison between normal and fraudulent transactions.
Figure C15.1 — Transaction amount comparison between normal and fraudulent transactions.
Figure C15.2 — Fraud rate (%) by hour of day.
Figure C15.2 — Fraud rate (%) by hour of day.

C15.9  Key Insights

C15.10  Business Recommendations

✓ Instructor Tip
This project is an excellent bridge to any future Machine Learning module the institute may add — frame it as 'fraud detection before ML' to set that expectation with students.