A machine learning system for real-time credit card fraud detection using MLflow, FastAPI, Kafka, and Streamlit.
- Docker and Docker Compose
- Python 3.9+
- Git
- Clone the repository:
git clone git@github.com:Thejaswi05/realtime_fraud_detection.git
cd realtime-fraud-detection
2. Create and activate a virtual environment (optional but recommended):
```bash
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Start all services:
# Clean start
docker-compose down -v
docker-compose up -d- Train the model:
docker-compose run --rm train- Access the services:
- MLflow UI: http://localhost:5001
- Model Playground: http://localhost:8501
- API Documentation: http://localhost:8000/docs
The Streamlit playground provides an interactive interface to test the fraud detection model.
-
Access the playground at http://localhost:8501
-
Input transaction details:
- Amount: Enter the transaction amount in dollars
- Time: Select the transaction's position in the sequence
-
Click "Check for Fraud" to get predictions
-
Understand the results:
- Prediction: Shows if the transaction is legitimate or fraudulent
- Confidence: Shows the model's confidence in its prediction
- Feature Analysis: Displays the top 10 influential features
- Blue bars (positive values): Transaction patterns the model has learned
- Red bars (negative values): Different transaction patterns
- Bar length: Strength of the feature's influence
- The combination of all features determines the final prediction
-
Feature Interpretation:
- Time: Position in transaction sequence (helps detect patterns)
- Amount: Transaction value
- V1-V28: Anonymized transaction characteristics
To modify the system:
- Update model training:
3. Update playground:
```bash
docker-compose restart playground
- Port conflicts:
# Stop all containers and remove volumes
docker-compose down -v
# Check for running containers
docker ps
# Kill specific ports if needed
sudo lsof -i :5001 # Check MLflow port
sudo lsof -i :8501 # Check Streamlit port- MLflow connection issues:
# Restart MLflow
docker-compose restart mlflow
# Check logs
docker-compose logs mlflow- Model loading errors:
# Ensure model is trained
docker-compose run --rm train
# Check MLflow UI for successful runs- Fork the repository
- Create a feature branch
- Commit changes
- Push to the branch
- Create a Pull Request
- Provides clear installation steps
- Explains how to run each component
- Details the Streamlit playground usage
- Includes troubleshooting guides
- Explains project structure