How juniorcl/transaction-fraud-detection works
Project type and purpose
• This is a data-science project for transaction fraud detection, culminating in a lightweight Flask API that serves a trained XGBoost model.
• Its primary purpose is to take incoming transaction data, apply preprocessing (scaling, one-hot encoding), run the model, and return a fraud/non-fraud prediction.
File structure
Top-level directories:
• api/ ← Flask service
– handler.py
– fraud/Fraud.py ← logic to load artifacts and serve predictions
• data/ ← raw data storage
– raw/fraud_0.1origbase.csv
• functions/← serialized preprocessing artifacts
– minmaxscaler_cycle1.joblib
– onehotencoder_cycle1.joblib
• models/ ← serialized trained model
– model_cycle1.joblib
• notebooks/← exploratory EDA and training pipeline in Jupyter
• reports/ ← figures and business results
• requirements.txt, README.md, LICENSE
README for additional insights
• Confirms a 10-step data science workflow from data description → EDA → feature engineering → model training → hyperparameter tuning → deployment.
• Final step “Model Deploy” uses Flask and joblib artifacts.
Main components
1. Data Source
• CSV store (data/raw)
• (Future: production database or streaming source)
2. Data Processing & Model Training (Offline Batch Pipeline)
• Jupyter Notebook component (notebooks/)
• Preprocessing jobs:
– min-max scaler
– one-hot encoder
• Feature selection & model training (XGBoost)
• Model registry (models/model_cycle1.joblib) and preprocessing artifacts (functions/*.joblib)
3. Model Serving (Flask API)
• API Container (api/handler.py)
• Fraud module (api/fraud/Fraud.py) loads joblib artifacts
• HTTP endpoint(s) receive JSON transaction → preprocess → predict → JSON response
4. Client / Consumer
• External client (web app, batch job, mobile app) invoking the HTTP REST endpoint
5. Reporting & Monitoring (Optional)
• reports/ figures archive
• (Future: add metrics store or dashboard)
Relationships & interactions
• Offline pipeline reads raw CSV → transforms → fits model → exports artifacts.
• Serving container mounts or loads artifacts at start-up.
• Client → HTTP POST → Flask API → Fraud.py pipeline → joblib scaler → joblib encoder → joblib model → response.
• (Optional) Logs metrics or stores predictions in a database.
Architectural patterns & design principles
• Separation of concerns:
• Offline ETL & training vs. online inference
• Preprocessing artifacts decoupled from code, loaded at runtime
• Modular design: each component (scaler, encoder, model) is its own artifact and function.
• Microservice: single‐purpose Flask API for inference.
Relevant technologies & frameworks
• Python 3.x
• Flask (api/handler.py)
• joblib (serialize/deserialize scaler, encoder, model)
• XGBoost (model training library)
• Jupyter Notebooks (EDA & prototyping)
Detail is crucial
• Every key module (minmaxscaler, onehotencoder, model) as its own node.
• “api/fraud/Fraud.py” component separately from handler.py.