Bjerring98 commited on
Commit
7333c2c
·
verified ·
1 Parent(s): 199a766

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -5
app.py CHANGED
@@ -446,13 +446,25 @@ elif option == "Financial Recommender Engine":
446
  else:
447
  st.write("Click the 'Get Recommendations' button to receive personalized financial recommendations.")
448
 
 
449
  elif option == "SML Classification":
450
  st.markdown("<h2 style='text-align: center;'>SML Classification</h2>", unsafe_allow_html=True)
451
 
 
 
 
 
 
 
 
 
 
 
 
452
  # Collect user inputs
453
  place_of_living = st.selectbox('Place of Living', ['Urban Area', 'Rural Area', 'Unknown'])
454
  education_level = st.selectbox('Education Level', ['Primary', 'Secondary', 'Tertiary'])
455
- age_group = st.selectbox('Age Group', ['Adult', 'Middle Age', 'Older Adult', 'Senior', 'Teen', 'Young Adult'])
456
  income_bracket = st.selectbox('Income Bracket', [1, 2, 3, 4, 5])
457
  female = st.radio('Gender', ['Female', 'Male'])
458
  is_mobileowner = st.checkbox('Is Mobile Owner?')
@@ -473,11 +485,12 @@ elif option == "SML Classification":
473
  'Has Internet Access': [1 if has_internet_access else 0],
474
  'Employed': [1 if employed else 0],
475
  'High Income Region': [1 if high_income_region else 0],
476
- 'Income Bracket': [income_bracket] # Directly use Income Bracket as numerical
477
  })
478
 
 
479
  cat_encoded = pd.DataFrame(ohe.transform(cat_features),
480
- columns=ohe.get_feature_names_out(['Place of living', 'Education Level', 'Age Group']))
481
 
482
  # Combine categorical and numerical features
483
  features = pd.concat([num_features, cat_encoded], axis=1)
@@ -487,8 +500,11 @@ elif option == "SML Classification":
487
  # Make the prediction
488
  predicted_saved = xgb_model.predict(features)[0]
489
 
490
- # Display prediction result
491
- st.metric(label="Predicted Probability of Saving", value=f'{round(predicted_saved * 100, 2)}%')
 
 
 
492
 
493
  # SHAP explanation
494
  st.subheader('Feature Contributions 🤖')
 
446
  else:
447
  st.write("Click the 'Get Recommendations' button to receive personalized financial recommendations.")
448
 
449
+
450
  elif option == "SML Classification":
451
  st.markdown("<h2 style='text-align: center;'>SML Classification</h2>", unsafe_allow_html=True)
452
 
453
+ # Age group labels with age ranges
454
+ age_group_labels = [
455
+ 'Teen (13-18)',
456
+ 'Young Adult (19-24)',
457
+ 'Adult (25-34)',
458
+ 'Middle Age (35-44)',
459
+ 'Older Adult (45-54)',
460
+ 'Senior (55-64)',
461
+ 'Elder (65-110)'
462
+ ]
463
+
464
  # Collect user inputs
465
  place_of_living = st.selectbox('Place of Living', ['Urban Area', 'Rural Area', 'Unknown'])
466
  education_level = st.selectbox('Education Level', ['Primary', 'Secondary', 'Tertiary'])
467
+ age_group = st.selectbox('Age Group', age_group_labels) # Dropdown with age ranges
468
  income_bracket = st.selectbox('Income Bracket', [1, 2, 3, 4, 5])
469
  female = st.radio('Gender', ['Female', 'Male'])
470
  is_mobileowner = st.checkbox('Is Mobile Owner?')
 
485
  'Has Internet Access': [1 if has_internet_access else 0],
486
  'Employed': [1 if employed else 0],
487
  'High Income Region': [1 if high_income_region else 0],
488
+ 'Income Bracket': [income_bracket]
489
  })
490
 
491
+ # OneHotEncode only the categorical variables
492
  cat_encoded = pd.DataFrame(ohe.transform(cat_features),
493
+ columns=ohe.get_feature_names_out(['Place of living', 'Education Level', 'Age Group']))
494
 
495
  # Combine categorical and numerical features
496
  features = pd.concat([num_features, cat_encoded], axis=1)
 
500
  # Make the prediction
501
  predicted_saved = xgb_model.predict(features)[0]
502
 
503
+ # Display saving habit likelihood instead of probability
504
+ if predicted_saved >= 0.5:
505
+ st.success("Saving habit is likely.")
506
+ else:
507
+ st.error("Saving habit is unlikely.")
508
 
509
  # SHAP explanation
510
  st.subheader('Feature Contributions 🤖')