Update src/streamlit_app.py
Browse files- src/streamlit_app.py +7 -13
src/streamlit_app.py
CHANGED
|
@@ -35,21 +35,20 @@ else:
|
|
| 35 |
# ================= TITLE =================
|
| 36 |
st.title("π³ Credit Card Fraud Detection")
|
| 37 |
st.markdown("Real-time fraud detection using Machine Learning.")
|
|
|
|
| 38 |
st.markdown("""
|
| 39 |
### π§ How the model works
|
| 40 |
-
|
| 41 |
The model evaluates each transaction using three types of signals:
|
| 42 |
|
| 43 |
- β± **Time** β seconds since the first recorded transaction
|
| 44 |
- π° **Amount** β transaction value
|
| 45 |
- π **V1βV28** β anonymized PCA components capturing hidden behavioral patterns
|
| 46 |
|
| 47 |
-
These components
|
| 48 |
-
They are mathematical transformations of the original transaction data used to protect sensitive financial information while preserving the patterns needed for fraud detection.
|
| 49 |
""")
|
| 50 |
|
| 51 |
tab1, tab2 = st.tabs(["π Prediction", "π Model Insights"])
|
| 52 |
-
|
| 53 |
# ================= TAB 1 β PREDICTION =================
|
| 54 |
with tab1:
|
| 55 |
|
|
@@ -69,15 +68,14 @@ with tab1:
|
|
| 69 |
with col2:
|
| 70 |
amount = st.number_input("Amount", value=0.0)
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
st.info("""
|
| 75 |
V1βV28 are PCA-transformed features.
|
| 76 |
-
|
| 77 |
The original transaction variables are anonymized for privacy.
|
| 78 |
These components capture hidden transaction patterns used by the model to detect fraud.
|
| 79 |
""")
|
| 80 |
-
|
|
|
|
|
|
|
| 81 |
with st.expander("PCA Features (Anonymized Transaction Patterns)"):
|
| 82 |
for i in range(28):
|
| 83 |
val = st.number_input(f"V{i+1}", value=0.0)
|
|
@@ -114,20 +112,16 @@ with tab2:
|
|
| 114 |
st.info("Test data not found. Upload X_test.npy and y_test.npy to enable insights.")
|
| 115 |
|
| 116 |
else:
|
| 117 |
-
|
| 118 |
st.metric("AUC", round(auc, 3))
|
| 119 |
|
| 120 |
-
# ROC Curve
|
| 121 |
fig, ax = plt.subplots()
|
| 122 |
RocCurveDisplay.from_predictions(y_test, y_prob, ax=ax)
|
| 123 |
st.pyplot(fig)
|
| 124 |
|
| 125 |
-
# Confusion Matrix
|
| 126 |
fig2, ax2 = plt.subplots()
|
| 127 |
ConfusionMatrixDisplay.from_predictions(y_test, y_pred, ax=ax2)
|
| 128 |
st.pyplot(fig2)
|
| 129 |
|
| 130 |
-
# Feature importance (tree-based models only)
|
| 131 |
if hasattr(model, "feature_importances_"):
|
| 132 |
|
| 133 |
st.subheader("Feature Importance")
|
|
|
|
| 35 |
# ================= TITLE =================
|
| 36 |
st.title("π³ Credit Card Fraud Detection")
|
| 37 |
st.markdown("Real-time fraud detection using Machine Learning.")
|
| 38 |
+
|
| 39 |
st.markdown("""
|
| 40 |
### π§ How the model works
|
|
|
|
| 41 |
The model evaluates each transaction using three types of signals:
|
| 42 |
|
| 43 |
- β± **Time** β seconds since the first recorded transaction
|
| 44 |
- π° **Amount** β transaction value
|
| 45 |
- π **V1βV28** β anonymized PCA components capturing hidden behavioral patterns
|
| 46 |
|
| 47 |
+
These components are mathematical transformations of the original data and are not directly interpretable.
|
|
|
|
| 48 |
""")
|
| 49 |
|
| 50 |
tab1, tab2 = st.tabs(["π Prediction", "π Model Insights"])
|
| 51 |
+
|
| 52 |
# ================= TAB 1 β PREDICTION =================
|
| 53 |
with tab1:
|
| 54 |
|
|
|
|
| 68 |
with col2:
|
| 69 |
amount = st.number_input("Amount", value=0.0)
|
| 70 |
|
| 71 |
+
st.info("""
|
|
|
|
|
|
|
| 72 |
V1βV28 are PCA-transformed features.
|
|
|
|
| 73 |
The original transaction variables are anonymized for privacy.
|
| 74 |
These components capture hidden transaction patterns used by the model to detect fraud.
|
| 75 |
""")
|
| 76 |
+
|
| 77 |
+
pca_values = []
|
| 78 |
+
|
| 79 |
with st.expander("PCA Features (Anonymized Transaction Patterns)"):
|
| 80 |
for i in range(28):
|
| 81 |
val = st.number_input(f"V{i+1}", value=0.0)
|
|
|
|
| 112 |
st.info("Test data not found. Upload X_test.npy and y_test.npy to enable insights.")
|
| 113 |
|
| 114 |
else:
|
|
|
|
| 115 |
st.metric("AUC", round(auc, 3))
|
| 116 |
|
|
|
|
| 117 |
fig, ax = plt.subplots()
|
| 118 |
RocCurveDisplay.from_predictions(y_test, y_prob, ax=ax)
|
| 119 |
st.pyplot(fig)
|
| 120 |
|
|
|
|
| 121 |
fig2, ax2 = plt.subplots()
|
| 122 |
ConfusionMatrixDisplay.from_predictions(y_test, y_pred, ax=ax2)
|
| 123 |
st.pyplot(fig2)
|
| 124 |
|
|
|
|
| 125 |
if hasattr(model, "feature_importances_"):
|
| 126 |
|
| 127 |
st.subheader("Feature Importance")
|