This repository contains a fraud-detection workflow built around the IEEE-CIS / Vesta e-commerce fraud dataset. It includes a model-training notebook, a Streamlit app for live prediction, the raw CSV inputs, and the saved model artifacts needed to run inference.
The training pipeline uses a hybrid machine-learning approach:
- Missing values are filled with
-999. - Categorical features are label-encoded.
- Features are scaled with
StandardScaler. KMeansis used as an additional engineered feature.- Class imbalance is handled with
SMOTE. - Multiple models are trained and compared, including Logistic Regression, Decision Tree, Random Forest, Optuna-tuned XGBoost, and LightGBM.
The notebook evaluates models with F1 score, ROC-AUC, confusion matrix, and classification report, then saves the inference artifacts used by the app.
app.py- Streamlit web app for live fraud prediction.Fraud-Detection.ipynb- End-to-end training and evaluation notebook.transaction.csv- Main transaction dataset.identity.csv- Identity metadata joined with the transaction data.xgb_model.pkl- Saved XGBoost model used by the app.lgbm_model.pkl- Saved LightGBM model used by the app.scaler.pkl- Saved scaler used during preprocessing.kmeans.pkl- Saved KMeans clustering model used as a hybrid feature.
The Streamlit app in app.py provides:
- An introduction page describing the fraud-detection problem, dataset, and pipeline.
- A live prediction demo where users enter transaction details and select either the XGBoost or LightGBM model.
- A probability-based risk view with fraud probability, confidence, and a visual risk meter.
Install the project dependencies from requirements.txt:
pip install -r requirements.txtIf you want to work with the notebook, also make sure Jupyter is installed:
pip install notebook ipykernelpython -m venv .venv
.venv\\Scripts\\activatepip install -r requirements.txtstreamlit run app.pyThe app expects xgb_model.pkl, lgbm_model.pkl, scaler.pkl, and kmeans.pkl to be in the same folder as app.py.
Run Fraud-Detection.ipynb in Jupyter or VS Code to inspect the full training pipeline, reproduce the model comparisons, and regenerate the saved artifacts if needed.
- The dataset is highly imbalanced, with fraud representing a small fraction of transactions.
transaction.csvis large, so some editors may not preview it fully.- The app is designed for interactive demonstration, not for production risk scoring without further validation and monitoring.
- If the app shows missing model-file errors, confirm the
.pklfiles are in the project root. - If package import errors appear, verify the virtual environment is activated and all dependencies are installed.
- If the notebook fails on memory-heavy operations, reduce the dataset size for local experimentation or run it in an environment with more RAM.