fraud_detection / app.py
Foccuus's picture
Upload 2 files
4367cb3 verified
Raw
History Blame Contribute Delete
2.93 kB
import streamlit as st
import json, os
st.set_page_config(
page_title="Hybrid AI Fraud Detection",
page_icon="shield",
layout="wide",
initial_sidebar_state="expanded"
)
@st.cache_resource
def load_results():
results = {}
for name, path in [
("p1", "models/p1_lgbm_results.json"),
("p2", "models/p2_stacking_results.json"),
("p3", "models/p3_pipeline_results.json"),
]:
if os.path.exists(path):
with open(path) as f:
results[name] = json.load(f)
return results
results = load_results()
st.title("Hybrid AI Architectures for Proactive Fraud Detection")
st.subheader("An XAI-Driven Optimization Framework")
st.markdown("**Master MAII | FSTH - Universite Abdelmalek Essaadi | Latif SINARE**")
st.divider()
col1, col2, col3, col4 = st.columns(4)
with col1:
st.metric("Recall cible", ">= 90%")
with col2:
st.metric("FPR cible", "< 0,01%")
with col3:
st.metric("AUPRC cible", "> 0,85")
with col4:
st.metric("Precision min", ">= 10%")
st.divider()
col_a, col_b = st.columns(2)
with col_a:
st.markdown("### Architecture des Pipelines")
table_lines = [
"| Phase | Dataset | Modeles | Optimiseur | XAI |",
"|-------|---------|---------|------------|-----|",
"| 1 - Baseline | Kaggle CC | LightGBM | CMA-ES | SHAP |",
"| 2 - Prototype | PaySim | LSTM + RGAT + Stacking | PSO Async | GNNExplainer |",
"| 3 - Production | IEEE-CIS | LSTM + RGAT + Stacking | PSO Async | SHAP + GNN |",
"| 4 - Extension | AMLSim | RGAT | - | GNNExplainer |",
]
st.markdown(chr(10).join(table_lines))
with col_b:
st.markdown("### Fonction de Fitness Penalisee")
st.latex(r"fitness( heta) = AUPRC - 10\cdot\max(0, 0.90 - Recall) - 10\cdot\max(0, FPR - 0.0001)")
st.markdown("Cette fonction garantit simultanement le Recall >= 90 pourcent et le FPR < 0,01 pourcent.")
st.divider()
if results:
st.markdown("### Resultats disponibles")
cols = st.columns(len(results))
labels = {"p1": "Phase 1 - Kaggle CC", "p2": "Phase 2 - PaySim", "p3": "Phase 3 - IEEE-CIS"}
for i, (k, res) in enumerate(results.items()):
with cols[i]:
th = res.get("test_holdout", res.get("fusion_test", {}))
st.markdown(f"**{labels.get(k, k)}**")
auprc_val = th.get("auprc", 0)
recall_val = th.get("recall", 0)
fpr_val = th.get("fpr", 0)
st.metric("AUPRC", f"{auprc_val:.4f}")
st.metric("Recall", f"{recall_val:.4f}")
st.metric("FPR", f"{fpr_val:.6f}")
else:
st.info("Les resultats apparaitront ici au fur et a mesure de execution des notebooks 03, 08 et 11.")
st.divider()
st.info("Utilisez la barre laterale pour naviguer entre les pipelines et analyser des transactions individuelles.")