tajuarAkash commited on
Commit
2d1df34
·
verified ·
1 Parent(s): 868cd95

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import joblib
3
+ import numpy as np
4
+ import pandas as pd
5
+ from sklearn.preprocessing import StandardScaler
6
+
7
+ # Load the trained model from Hugging Face (if hosted there)
8
+ # You can replace 'tajuarAkash/my-model' with the actual repository name on Hugging Face
9
+ model = joblib.load('random_forest_model.joblib') # For local file if uploaded to Space
10
+
11
+ # Title and description for the app
12
+ st.title("Insurance Claim Fraud Detection")
13
+ st.write("""
14
+ This app predicts whether an insurance claim is fraudulent or legitimate based on user input.
15
+ Please enter the information below.
16
+ """)
17
+
18
+ # Input fields for users to provide claim details
19
+ claim_amount = st.number_input("Enter the claim amount", min_value=0)
20
+ patient_age = st.number_input("Enter the patient's age", min_value=0)
21
+ patient_income = st.number_input("Enter the patient's income", min_value=0)
22
+ patient_gender = st.selectbox("Select patient's gender", ["Male", "Female"])
23
+ claim_status = st.selectbox("Claim status", ["Denied", "Pending", "Approved"])
24
+
25
+ # Create a button to trigger prediction
26
+ if st.button('Predict Fraud'):
27
+ # Preprocess the input data (this may need adjustments based on how you preprocessed during training)
28
+ input_data = {
29
+ "ClaimAmount": [claim_amount],
30
+ "PatientAge": [patient_age],
31
+ "PatientIncome": [patient_income],
32
+ "PatientGender": [patient_gender],
33
+ "ClaimStatus": [claim_status],
34
+ }
35
+
36
+ # Convert the input data to a pandas DataFrame
37
+ input_df = pd.DataFrame(input_data)
38
+
39
+ # Encode the gender (if needed)
40
+ input_df['PatientGender'] = input_df['PatientGender'].apply(lambda x: 1 if x == 'Male' else 0)
41
+
42
+ # Encode the ClaimStatus (example ordinal encoding, adjust based on training)
43
+ claim_status_mapping = {"Denied": 0, "Pending": 1, "Approved": 2}
44
+ input_df['ClaimStatus'] = input_df['ClaimStatus'].map(claim_status_mapping)
45
+
46
+ # Assuming the model expects the data to be scaled (adjust as per your preprocessing)
47
+ scaler = StandardScaler()
48
+ input_scaled = scaler.fit_transform(input_df)
49
+
50
+ # Get the prediction from the model
51
+ prediction = model.predict(input_scaled)
52
+
53
+ # Display the result
54
+ if prediction == 1:
55
+ st.write("This claim is predicted to be **fraudulent**.")
56
+ else:
57
+ st.write("This claim is predicted to be **legitimate**.")
58
+