Hey everyone! ![]()
I just deployed Fraud Shield, an end-to-end credit card fraud detection app — sharing it here in case it’s useful to anyone working on classification problems or looking for Streamlit UI ideas.
Live app: https://musfirah-credit-card-fraud-detection.streamlit.app/
The problem
The dataset (Kaggle’s classic credit card fraud dataset) has 284,807 transactions, but only 492 (0.17%) are fraud. That imbalance makes accuracy a useless metric — a model that never flags fraud would still score 99.8% accuracy while catching nothing.
What I built
- Trained and tuned 6 classification models with GridSearchCV: Logistic Regression, SGD, Decision Tree, Random Forest, HistGradientBoosting, and Naive Bayes
- Handled the imbalance with
class_weight='balanced'instead of oversampling - Evaluated on F1, ROC-AUC, Precision, and Recall instead of accuracy
- Random Forest won (F1: 0.775, ROC-AUC: 0.983, Recall: 82.7%)
- Extracted real feature importance from the winning model so the UI’s interactive sliders reflect what the model actually learned, not generic guesses
The Streamlit app has 5 pages:
Home — best model snapshot + scores
Single Prediction — check a transaction manually, or load a real one from the dataset to see guaranteed-correct model behavior
Batch Prediction — upload a CSV, get predictions for every row, download results
Model Performance — full comparison across all 6 models with charts
About Me — a bit about who built it
One Streamlit feature I leaned on a lot: st.session_state to let users toggle between “load a real example” mode and manual slider mode without losing state on rerun. Happy to share more detail on that if anyone’s running into similar session_state gotchas.
Which model do you think works best for imbalanced data? Let me know in the replies!
Would love feedback, especially on the UI/UX side — first real Streamlit app I’ve deployed! ![]()
**Support the Project:**
If you find this project or the Streamlit UI implementation useful, please consider giving it a **
** on the GitHub repository! It keeps me motivated to build more open-source tools.
#MachineLearning #FraudDetection streamlit #Python #ScikitLearn
