tajuarAkash commited on
Commit
c20ddd8
·
verified ·
1 Parent(s): 3b01c14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -14
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']], # Wrapped in list
28
- 'ClaimAmount': [input_data['ClaimAmount']], # Wrapped in list
29
- 'PatientAge': [input_data['PatientAge']], # Wrapped in list
30
- 'PatientIncome': [input_data['PatientIncome']], # Wrapped in list
31
- 'PatientGender': [input_data['PatientGender']], # Wrapped in list
32
- 'ProviderSpecialty': [input_data['ProviderSpecialty']], # Wrapped in list
33
- 'ClaimStatus': [input_data['ClaimStatus']], # Wrapped in list
34
- 'PatientMaritalStatus': [input_data['PatientMaritalStatus']], # Wrapped in list
35
- 'PatientEmploymentStatus': [input_data['PatientEmploymentStatus']], # Wrapped in list
36
- 'ProviderLocation': [input_data['ProviderLocation']], # Wrapped in list
37
- 'ClaimType': [input_data['ClaimType']], # Wrapped in list
38
- 'ClaimSubmissionMethod': [input_data['ClaimSubmissionMethod']], # Wrapped in list
39
  })
40
 
41
- # Assuming ML preprocessing: Encoding and scaling (use the same scaler and encoders as in training)
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("""