Update app.py
Browse files
app.py
CHANGED
@@ -22,23 +22,27 @@ rf_model = joblib.load(rf_model_path)
|
|
22 |
def preprocess_input(input_data, method="ml"):
|
23 |
if method == "ml":
|
24 |
# For Random Forest prediction, apply necessary transformations like scaling or encoding.
|
|
|
|
|
|
|
|
|
25 |
# Wrap each feature value in a list to create a valid DataFrame
|
26 |
input_df = pd.DataFrame({
|
27 |
-
'ClaimDate': [input_data['ClaimDate']], #
|
28 |
-
'ClaimAmount': [input_data['ClaimAmount']],
|
29 |
-
'PatientAge': [input_data['PatientAge']],
|
30 |
-
'PatientIncome': [input_data['PatientIncome']],
|
31 |
-
'PatientGender': [input_data['PatientGender']],
|
32 |
-
'ProviderSpecialty': [input_data['ProviderSpecialty']],
|
33 |
-
'ClaimStatus': [input_data['ClaimStatus']],
|
34 |
-
'PatientMaritalStatus': [input_data['PatientMaritalStatus']],
|
35 |
-
'PatientEmploymentStatus': [input_data['PatientEmploymentStatus']],
|
36 |
-
'ProviderLocation': [input_data['ProviderLocation']],
|
37 |
-
'ClaimType': [input_data['ClaimType']],
|
38 |
-
'ClaimSubmissionMethod': [input_data['ClaimSubmissionMethod']],
|
39 |
})
|
40 |
|
41 |
-
#
|
42 |
input_df['PatientGender'] = input_df['PatientGender'].apply(lambda x: 1 if x == 'Male' else 0)
|
43 |
claim_status_mapping = {"Denied": 0, "Pending": 1, "Approved": 2}
|
44 |
input_df['ClaimStatus'] = input_df['ClaimStatus'].map(claim_status_mapping)
|
@@ -47,7 +51,6 @@ def preprocess_input(input_data, method="ml"):
|
|
47 |
input_scaled = scaler.fit_transform(input_df) # Scaling the data
|
48 |
|
49 |
return input_scaled
|
50 |
-
|
51 |
elif method == "nlp":
|
52 |
# For NLP-based prediction, concatenate features into a single paragraph
|
53 |
claim_date = input_data['ClaimDate']
|
@@ -78,6 +81,7 @@ def preprocess_input(input_data, method="ml"):
|
|
78 |
|
79 |
|
80 |
|
|
|
81 |
# Title and description for the app
|
82 |
st.title("Insurance Claim Fraud Detection")
|
83 |
st.write("""
|
|
|
22 |
def preprocess_input(input_data, method="ml"):
|
23 |
if method == "ml":
|
24 |
# For Random Forest prediction, apply necessary transformations like scaling or encoding.
|
25 |
+
|
26 |
+
# Convert ClaimDate to ordinal (number of days since a particular date)
|
27 |
+
input_data['ClaimDate'] = pd.to_datetime(input_data['ClaimDate']).apply(lambda date: date.toordinal())
|
28 |
+
|
29 |
# Wrap each feature value in a list to create a valid DataFrame
|
30 |
input_df = pd.DataFrame({
|
31 |
+
'ClaimDate': [input_data['ClaimDate']], # Now converted to ordinal value
|
32 |
+
'ClaimAmount': [input_data['ClaimAmount']],
|
33 |
+
'PatientAge': [input_data['PatientAge']],
|
34 |
+
'PatientIncome': [input_data['PatientIncome']],
|
35 |
+
'PatientGender': [input_data['PatientGender']],
|
36 |
+
'ProviderSpecialty': [input_data['ProviderSpecialty']],
|
37 |
+
'ClaimStatus': [input_data['ClaimStatus']],
|
38 |
+
'PatientMaritalStatus': [input_data['PatientMaritalStatus']],
|
39 |
+
'PatientEmploymentStatus': [input_data['PatientEmploymentStatus']],
|
40 |
+
'ProviderLocation': [input_data['ProviderLocation']],
|
41 |
+
'ClaimType': [input_data['ClaimType']],
|
42 |
+
'ClaimSubmissionMethod': [input_data['ClaimSubmissionMethod']],
|
43 |
})
|
44 |
|
45 |
+
# Apply necessary preprocessing: Encoding and scaling (use the same scaler and encoders as in training)
|
46 |
input_df['PatientGender'] = input_df['PatientGender'].apply(lambda x: 1 if x == 'Male' else 0)
|
47 |
claim_status_mapping = {"Denied": 0, "Pending": 1, "Approved": 2}
|
48 |
input_df['ClaimStatus'] = input_df['ClaimStatus'].map(claim_status_mapping)
|
|
|
51 |
input_scaled = scaler.fit_transform(input_df) # Scaling the data
|
52 |
|
53 |
return input_scaled
|
|
|
54 |
elif method == "nlp":
|
55 |
# For NLP-based prediction, concatenate features into a single paragraph
|
56 |
claim_date = input_data['ClaimDate']
|
|
|
81 |
|
82 |
|
83 |
|
84 |
+
|
85 |
# Title and description for the app
|
86 |
st.title("Insurance Claim Fraud Detection")
|
87 |
st.write("""
|