Skip to content

πŸ” Advanced fraud detection system using Self-Organizing Maps for anomaly detection and Neural Networks for classification

License

Notifications You must be signed in to change notification settings

Ahmadhammam03/credit-card-fraud-detection-som

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Credit Card Fraud Detection using Self-Organizing Maps (SOM) and Artificial Neural Networks

Python TensorFlow License

🎯 Project Overview

This project implements a comprehensive fraud detection system for credit card applications using Self-Organizing Maps (SOM) for unsupervised anomaly detection, followed by an Artificial Neural Network (ANN) for supervised classification. The system effectively identifies fraudulent credit card applications with high accuracy.

πŸš€ Key Features

  • Unsupervised Learning: Uses SOM to identify potential fraud patterns without labeled data
  • Supervised Learning: Implements ANN for final fraud classification
  • Data Visualization: Interactive maps showing fraud clusters
  • Scalable Architecture: Modular design for easy extension and modification
  • Comprehensive Analysis: Detailed exploratory data analysis and results interpretation

πŸ“Š Dataset

The project uses the Credit Card Applications Dataset containing:

  • 690 applications with 15 features each
  • Anonymized attributes (A1-A15) for privacy protection
  • Binary classification: Approved (1) vs Rejected (0) applications

Dataset Features:

  • Customer demographic information
  • Financial attributes
  • Credit history indicators
  • Application-specific details

πŸ› οΈ Technologies Used

  • Python 3.8+
  • TensorFlow/Keras - Neural network implementation
  • Scikit-learn - Data preprocessing and evaluation
  • MiniSOM - Self-Organizing Maps implementation
  • Pandas - Data manipulation and analysis
  • NumPy - Numerical computations
  • Matplotlib - Data visualization
  • Seaborn - Statistical plotting

πŸ“ Project Structure

credit-card-fraud-detection-som/
β”‚
β”œβ”€β”€ data/
β”‚   └── Credit_Card_Applications.csv
β”‚
β”œβ”€β”€ notebooks/
β”‚   β”œβ”€β”€ som.ipynb                    # SOM implementation
β”‚   └── mega_case_study.ipynb        # Complete analysis
β”‚
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ data_preprocessing.py
β”‚   β”œβ”€β”€ som_model.py
β”‚   β”œβ”€β”€ ann_model.py
β”‚   └── visualization.py
β”‚
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ README.md
└── LICENSE

πŸ”§ Installation & Setup

  1. Clone the repository:

    git clone https://github.com/Ahmadhammam03/credit-card-fraud-detection-som.git
    cd credit-card-fraud-detection-som
  2. Create a virtual environment:

    python -m venv fraud_detection_env
    source fraud_detection_env/bin/activate  # On Windows: fraud_detection_env\Scripts\activate
  3. Install required packages:

    pip install -r requirements.txt

🚦 Quick Start

Running the SOM Analysis

# Import required libraries
import numpy as np
import pandas as pd
from minisom import MiniSom
from sklearn.preprocessing import MinMaxScaler

# Load and preprocess data
dataset = pd.read_csv('data/Credit_Card_Applications.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, -1].values

# Feature scaling
sc = MinMaxScaler(feature_range=(0, 1))
X = sc.fit_transform(X)

# Train SOM
som = MiniSom(x=10, y=10, input_len=15, sigma=1.0, learning_rate=0.5)
som.random_weights_init(X)
som.train_random(data=X, num_iteration=100)

# Identify fraud patterns
mappings = som.win_map(X)
frauds = np.concatenate((mappings[(8,1)], mappings[(6,9)]), axis=0)

Running the Complete Analysis

# Run the Jupyter notebook
jupyter notebook notebooks/mega_case_study.ipynb

πŸ“ˆ Results & Performance

SOM Results:

  • Successfully identified 14 potential fraud cases from unlabeled data
  • Created visual fraud detection map with clear anomaly clusters
  • Fraud patterns concentrated in specific SOM regions

ANN Results:

  • Training Accuracy: ~99.5% after 10 epochs
  • Fraud Detection Rate: High precision in identifying fraudulent applications
  • Model Architecture: 2 hidden layers with optimized parameters

Key Insights:

  1. Fraudulent applications show distinct patterns in financial attributes
  2. Geographic clustering of fraud cases in SOM visualization
  3. Effective combination of unsupervised and supervised learning approaches

πŸ” Methodology

Phase 1: Unsupervised Learning (SOM)

  1. Data Preprocessing: Feature scaling using MinMaxScaler
  2. SOM Training: 10x10 grid with 100 iterations
  3. Anomaly Detection: Identification of outlier clusters
  4. Visualization: Color-coded fraud detection map

Phase 2: Supervised Learning (ANN)

  1. Feature Engineering: Using SOM results as additional features
  2. Neural Network Design: 2-layer architecture with sigmoid activation
  3. Training: Binary classification with Adam optimizer
  4. Evaluation: Comprehensive performance metrics

πŸ“Š Visualizations

The project includes several key visualizations:

  • SOM Distance Map: Showing fraud clusters and patterns
  • Training Progress: Neural network convergence plots
  • Fraud Distribution: Geographic and feature-based analysis
  • Performance Metrics: ROC curves and confusion matrices

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘¨β€πŸ’» Author

Ahmad Hammam

πŸ™ Acknowledgments

  • Original dataset source and research community
  • MiniSOM library developers
  • TensorFlow and Scikit-learn communities
  • Open source machine learning community

πŸ“š References


⭐ If you found this project helpful, please give it a star! ⭐

About

πŸ” Advanced fraud detection system using Self-Organizing Maps for anomaly detection and Neural Networks for classification

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published