Fraud Detection MLOps Pipeline with Explainable AI
Decifra is a production-ready machine learning operations (MLOps) pipeline designed for credit card fraud detection. The system not only identifies fraudulent transactions with high accuracy but also provides transparent, interpretable explanations for each prediction using state-of-the-art Explainable AI (XAI) techniques.
The name "Decifra" derives from "to decipher" - representing the project's core mission of uncovering hidden fraud patterns and making AI decisions transparent and understandable.
| Metric | Before Tuning | After Optuna (100 trials) |
|---|---|---|
| PR-AUC | 84.91% | 88.52% |
| Precision | 39.91% | 87% |
| Recall | 86.73% | 86% |
| F1 Score | 54.66% | 86% |
π€ Live Demo on Hugging Face
Dashboard Interface - Real-time fraud detection with explainability
Model Performance Metrics - PR-AUC: 88.52%
End-to-end MLOps Pipeline Architecture
- Quick Start
- Overview
- Key Features
- Technology Stack
- Project Architecture
- Project Structure
- Installation
- Configuration
- Usage
- MLOps Pipeline
- Explainability
- API Reference
- Dashboard
- Testing
- Contributing
- License
# Clone repository
git clone https://github.com/HarshTomar1234/decifra.git
cd decifra
# Run with Docker Compose
docker-compose up --build
# Access:
# - Dashboard: http://localhost:8501
# - API: http://localhost:3000
# - MLflow: http://localhost:5000# Clone and setup
git clone https://github.com/HarshTomar1234/decifra.git
cd decifra
python -m venv .venv
.venv\Scripts\activate # Windows
pip install -e ".[dev]"
# Run training pipeline
python -m pipelines.training_pipeline
# Start BentoML API
python -m src.serving.save_model
bentoml serve src.serving.service:FraudDetectorService
# Launch Dashboard
streamlit run dashboard/app.pyFinancial fraud detection is a critical challenge in the banking and fintech industry. Traditional ML models often operate as "black boxes," providing predictions without explanations. This lack of transparency creates challenges for:
- Regulatory Compliance: Regulations like GDPR require explanations for automated decisions
- Fraud Analyst Trust: Investigators need to understand why transactions are flagged
- Model Debugging: Data scientists need insights to improve model performance
- Customer Experience: Reducing false positives requires understanding model behavior
Decifra addresses these challenges by combining robust fraud detection with comprehensive explainability.
- Multi-model training with XGBoost, LightGBM, and Random Forest
- Automated hyperparameter optimization using Optuna
- Handling of highly imbalanced datasets using SMOTE and stratified sampling
- Ensemble methods for improved prediction accuracy
- SHAP (SHapley Additive exPlanations) for global and local feature importance
- LIME (Local Interpretable Model-agnostic Explanations) for instance-level explanations
- Visual explanation reports for each prediction
- Feature contribution analysis for fraud decisions
- End-to-end pipeline orchestration with ZenML
- Experiment tracking and model registry with MLflow
- Data versioning with DVC
- Model serving and API deployment with BentoML
- Data validation with Great Expectations
- RESTful API for real-time predictions
- Interactive Streamlit dashboard for monitoring
- Docker containerization for deployment
- CI/CD pipeline with GitHub Actions
- Comprehensive logging and monitoring
| Category | Technology | Purpose |
|---|---|---|
| Orchestration | ZenML | ML pipeline orchestration and workflow management |
| Experiment Tracking | MLflow | Experiment logging, model registry, and artifact storage |
| Data Versioning | DVC | Version control for datasets and model artifacts |
| Model Serving | BentoML | Model packaging and REST API deployment |
| Explainability | SHAP, LIME | Model interpretation and explanation generation |
| ML Models | XGBoost, LightGBM, scikit-learn | Gradient boosting and ensemble methods |
| Hyperparameter Tuning | Optuna | Bayesian optimization for hyperparameters |
| Data Validation | Great Expectations | Data quality checks and schema validation |
| Dashboard | Streamlit | Interactive web interface for monitoring |
| API Framework | FastAPI | High-performance REST API endpoints |
| Containerization | Docker | Application containerization and deployment |
+-------------------+
| Streamlit |
| Dashboard |
+--------+----------+
|
+------------------+ +-------------------+|+-------------------+
| | | ||| |
| Raw Data +--->+ ZenML Pipeline +--> MLflow |
| (DVC Tracked) | | ||| Tracking |
| | +-------------------+|+-------------------+
+------------------+ | |
| |
+------------+ +------------+
| |
+--------v--------+ +--------v--------+
| | | |
| Trained Model | | BentoML API |
| (MLflow) +------------------>+ Service |
| | | |
+-----------------+ +--------+--------+
|
+--------v--------+
| |
| SHAP / LIME |
| Explanations |
| |
+-----------------+
decifra/
βββ src/ # Source code
β βββ config.py # Config loader (reads from configs/)
β βββ data/ # Data ingestion and preprocessing
β β βββ __init__.py
β β βββ ingestion.py # Data loading from sources
β β βββ preprocessing.py # Feature scaling, encoding
β β βββ validation.py # Data quality checks
β βββ features/ # Feature engineering
β β βββ __init__.py
β β βββ engineering.py # Feature transformations
β βββ models/ # Model definitions
β β βββ __init__.py
β β βββ tuner.py # Optuna hyperparameter tuning
β βββ explainability/ # XAI implementations
β β βββ __init__.py
β β βββ shap_explainer.py # SHAP explanations
β β βββ lime_explainer.py # LIME explanations
β βββ serving/ # Model serving
β βββ __init__.py
β βββ service.py # BentoML service
β βββ save_model.py # Model export to BentoML
βββ pipelines/ # ZenML pipelines
β βββ __init__.py
β βββ training_pipeline.py # Training workflow
β βββ steps/ # Pipeline steps
β βββ __init__.py
β βββ data_loader.py
β βββ preprocessor.py
β βββ trainer.py
β βββ evaluator.py
β βββ explainer.py
β βββ tuner.py # Hyperparameter tuning step
βββ dashboard/ # Streamlit application
β βββ app.py # Main dashboard
βββ configs/ # Configuration files
β βββ config.yaml # Hyperparameters & settings (SINGLE SOURCE OF TRUTH)
βββ data/ # Data directory
β βββ raw/ # Raw datasets
β βββ processed/ # Processed datasets
βββ artifacts/ # Generated artifacts
β βββ models/ # Trained models (including tuned)
β βββ explanations/ # SHAP & LIME plots
βββ notes/ # Learning notes
β βββ 01_zenml_pipelines.md
β βββ 02_mlflow_tracking.md
β βββ 03_bentoml_serving.md
β βββ 04_streamlit_dashboard.md
β βββ 05_optuna_tuning.md
βββ notebooks/ # Jupyter notebooks
βββ tests/ # Unit and integration tests
βββ docker/ # Docker configurations
βββ .dvc/ # DVC configuration
βββ .zen/ # ZenML configuration
βββ pyproject.toml # Project dependencies
βββ bentofile.yaml # BentoML build configuration
βββ .env.example # Environment template
βββ README.md # This file
- Python 3.9 or higher
- Git
- pip or conda
- Clone the repository:
git clone https://github.com/HarshTomar1234/decifra.git
cd decifra- Create and activate a virtual environment:
python -m venv .venv
# Windows
.venv\Scripts\activate
# Linux/macOS
source .venv/bin/activate- Install dependencies:
pip install -e ".[dev]"- Initialize ZenML:
zenml init- Configure environment variables:
cp .env.example .env
# Edit .env with your configurationThe main configuration file is located at configs/config.yaml. Key settings include:
data:
raw_path: "data/raw"
processed_path: "data/processed"
test_size: 0.2
random_state: 42models:
xgboost:
n_estimators: 100
max_depth: 6
learning_rate: 0.1explainability:
shap:
max_display: 20
lime:
num_features: 10Run the complete training pipeline:
python -m pipelines.training_pipelineView experiment tracking results:
mlflow ui --port 5000Access at: http://localhost:5000
First, save the model to BentoML:
python -m src.serving.save_modelThen deploy the model as a REST API:
bentoml serve src.serving.service:FraudDetectorServiceAccess API docs at: http://localhost:3000
Start the Streamlit monitoring dashboard:
streamlit run dashboard/app.pyThe ZenML training pipeline consists of the following steps:
- Data Ingestion: Load raw transaction data
- Data Validation: Verify data quality using Great Expectations
- Preprocessing: Handle missing values, scale features, apply SMOTE
- Feature Engineering: Create derived features
- Model Training: Train multiple models with hyperparameter tuning
- Model Evaluation: Calculate metrics (Precision, Recall, F1, ROC-AUC, PR-AUC)
- Model Selection: Select best performing model
- Explainability: Generate SHAP values and feature importance
- Model Registration: Register model in MLflow
SHAP provides both global and local explanations:
- Global: Overall feature importance across all predictions
- Local: Per-prediction feature contributions
LIME generates human-readable explanations by approximating model behavior locally around each prediction.
For a flagged transaction, the system provides:
- Fraud probability score
- Top contributing features (positive and negative)
- Visual waterfall chart of feature contributions
- Natural language explanation
| Method | Endpoint | Description |
|---|---|---|
| POST | /predict |
Get fraud prediction |
| POST | /predict_with_explanation |
Get prediction with SHAP/LIME explanation |
| GET | /health |
Health check |
| GET | /model_info |
Model metadata |
curl -X POST http://localhost:3000/predict \
-H "Content-Type: application/json" \
-d '{"features": [...]}'{
"prediction": 1,
"probability": 0.87,
"is_fraud": true,
"explanation": {
"top_features": [
{"feature": "V14", "contribution": 0.23},
{"feature": "V4", "contribution": 0.18}
]
}
}The Streamlit dashboard provides:
- Overview: Model performance metrics and confusion matrix
- Predictions: Real-time fraud scoring interface
- Explanations: Interactive SHAP and LIME visualizations
- Monitoring: Data drift detection and prediction distribution
- Analytics: Historical model performance trends
Run the test suite:
pytest tests/ -vRun with coverage:
pytest tests/ --cov=src --cov-report=html- Fork the repository
- Create a feature branch (
git checkout -b feature/new-feature) - Commit your changes (
git commit -m 'Add new feature') - Push to the branch (
git push origin feature/new-feature) - Open a Pull Request
This project is licensed under the MIT License. See the LICENSE file for details.
- Credit Card Fraud Detection Dataset from Kaggle
- ZenML, MLflow, DVC, and BentoML teams for excellent MLOps tools
- SHAP and LIME authors for XAI libraries

