Spaces:
Sleeping
Sleeping
import streamlit as st | |
import joblib | |
# Load the model | |
model = joblib.load("fraud_model.pkl") | |
# Real-world feature mappings | |
real_world_mapped_data = { | |
"-0.986639536": "Jamshidov Ozod", # Latitude of user's location | |
"0.054619774": "Tashkent", # Longitude of user's location (close to Tashkent) | |
"0.89218939": "3 seconds since the last transaction", # Time of transaction | |
"1.238546301": "100,000 UZS spent", # Amount spent | |
"1.153949202": "Xiaomi Phone", # Device used for transaction | |
"-0.443156858": "ATM withdrawal", # Transaction type | |
"1.158792971": "Afternoon (2 PM)", # Time of day | |
"-0.234932879": "5 transactions today", # Frequency of transactions | |
"-0.748284316": "10 km from user's home", # Distance from home location | |
"0.19999764": "50,000 UZS (past avg transaction amount)", # User's past avg transaction amount | |
"-0.377070284": "Retail store (Grocery)", # Merchant category | |
"-0.086545898": "Tashkent ATM branch", # Bank branch or ATM code | |
"0.217167156": "2,000,000 UZS spending limit", # User's spending limit | |
"0.314289834": "35 years old", # User's age | |
"1.295545516": "Frequent user behavior", # Transaction behavior | |
"-0.818801496": "1,500,000 UZS current account balance", # User's current balance | |
"0.059642158": "20 minutes between transactions", # Average time between transactions | |
"-0.68956288": "Middle-income category", # User's income category | |
"0.684420234": "Low-risk score", # User's risk score based on past behavior | |
"0.744324727": "750 credit score", # User's credit score | |
"-0.15608398": "Mobile app transaction", # Transaction channel | |
"-0.590576405": "Credit card", # Card type | |
"0.432953111": "2 failed login attempts", # Number of failed login attempts | |
"-0.337631423": "OTP verification", # Transaction approval method (e.g., OTP) | |
"-0.272390765": "1 hour since last login", # Time since last login | |
"-0.551474596": "Employed", # User's employment status | |
"0.171669591": "Transaction within Uzbekistan", # Transaction country | |
"0.012712389": "One-time purchase", # Transaction recurrence (single purchase) | |
"148.81": "148,810 UZS spent", # Transaction amount | |
"0.217684965": "3 days after first transaction", | |
"0.3333": "4 days after first transaction" # Transaction date | |
} | |
# Streamlit UI | |
st.title("Credit Card Fraud Detection") | |
st.write("### Test Case 1: Jamshidov Ozod") | |
if st.button("Run Fraud Detection on Test Case"): | |
# The mapped PCA values for the test case | |
mapped_pca_values = [ | |
-0.986639536, 0.054619774, 0.89218939, 1.238546301, 1.153949202, | |
-0.443156858, 1.158792971, -0.234932879, -0.748284316, 0.19999764, | |
-0.377070284, -0.086545898, 0.217167156, 0.314289834, 1.295545516, | |
-0.818801496, 0.059642158, -0.68956288, 0.684420234, 0.744324727, | |
-0.15608398, -0.590576405, 0.432953111, -0.337631423, -0.272390765, | |
-0.551474596, 0.171669591, 0.012712389, 148.81, 0.3333 | |
] | |
prediction = model.predict([mapped_pca_values]) | |
st.write(f"Prediction: {'Fraud' if prediction[0] == 1 else 'Non-fraud'}") | |
st.write("### Test Case 2: Positive Test") | |
if st.button("Run Fraud Detection on Positive Case"): | |
# Modify some values to simulate a fraudulent transaction | |
positive_case_values = [ | |
-4.5, 5.8, 1.2, 7.6, 3.1, | |
2.0, -1.5, 2.4, 5.5, 0.8, | |
2.2, -0.5, 3.7, 1.9, 4.3, | |
2.8, 3.1, 2.2, 4.5, 5.0, | |
2.1, 1.7, 1.9, -1.2, -0.8, | |
2.6, 1.5, 2.0, 75.8, 1.2 | |
] | |
prediction = model.predict([positive_case_values]) | |
st.write(f"Prediction: {'Fraud' if prediction[0] == 1 else 'Non-fraud'}") | |