AdisJulardzija commited on
Commit
19ae93f
·
verified ·
1 Parent(s): 02bf6a9

Upload 8 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ micro_world_139countries.csv filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import joblib
5
+ from xgboost import XGBRegressor
6
+ from sklearn.preprocessing import StandardScaler, OneHotEncoder
7
+ import shap
8
+ from streamlit_shap import st_shap
9
+
10
+
11
+
12
+ # Page configuration
13
+ st.set_page_config(
14
+ page_title="Medical Costs Concern Prediction",)
15
+
16
+ st.title('Predict Medical Costs Concern')
17
+
18
+ # Load model and preprocessing objects
19
+ @st.cache_resource
20
+ def load_model_objects():
21
+ model_xgb = joblib.load('model_best.joblib')
22
+ scaler = joblib.load('scaler.joblib')
23
+ return model_xgb, scaler
24
+
25
+ model_xgb, scaler = load_model_objects()
26
+ # Create SHAP explainer
27
+ explainer = shap.TreeExplainer(model_xgb)
28
+
29
+ # App description
30
+ with st.expander("What's this app?"):
31
+ st.markdown("""
32
+ This app predicts how worried a person is about medical costs, based on factors like age, education, income, and employment status.
33
+ We've trained an AI model to analyze these inputs and give a prediction.
34
+ """)
35
+
36
+ st.subheader('Describe yourself')
37
+
38
+ # User inputs
39
+ col1, col2 = st.columns(2)
40
+
41
+ with col1:
42
+ age = st.number_input('Age', min_value=18, max_value=100, value=30)
43
+ education = st.selectbox('Education Level', options=['Primary', 'Secondary', 'Tertiary'], index=1)
44
+ income_quartile = st.radio('Income Quartile', options=['Lowest', 'Second', 'Third', 'Highest'])
45
+
46
+ with col2:
47
+ employment_status = st.selectbox('Employment Status', options=['Unemployed', 'Employed', 'Self-employed', 'Student'], index=1)
48
+
49
+ # Map user inputs to numerical and categorical features
50
+ education_mapping = {'Primary': 1, 'Secondary': 2, 'Tertiary': 3}
51
+ income_mapping = {'Lowest': 1, 'Second': 2, 'Third': 3, 'Highest': 4}
52
+ employment_mapping = {'Unemployed': 0, 'Employed': 1, 'Self-employed': 2, 'Student': 3}
53
+
54
+ # Transform user input into a feature vector
55
+ education_num = education_mapping[education]
56
+ income_num = income_mapping[income_quartile]
57
+ employment_num = employment_mapping[employment_status]
58
+
59
+ # Prepare features for the model
60
+ num_features = pd.DataFrame({
61
+ 'age': [age],
62
+ 'educ': [education_num],
63
+ 'inc_q': [income_num],
64
+ 'emp_in': [employment_num]
65
+ })
66
+ num_scaled = pd.DataFrame(scaler.transform(num_features), columns=num_features.columns)
67
+
68
+ # Prediction button
69
+ if st.button('Predict Concern Level'):
70
+ # Make prediction
71
+ predicted_concern = model_xgb.predict(num_scaled)[0]
72
+ # Display prediction
73
+ st.metric(label="Predicted concern level", value=f'{round(predicted_concern)} (1: Not Worried, 3: Very Worried)')
74
+ # SHAP explanation
75
+ st.subheader('Concern Factors Explained')
76
+ shap_values = explainer.shap_values(num_scaled)
77
+ st_shap(shap.force_plot(explainer.expected_value, shap_values, num_scaled), height=400, width=600)
78
+ st.markdown("""
79
+ This plot shows how each feature contributes to the predicted concern level:
80
+ - Blue bars push the concern level lower
81
+ - Red bars push the concern level higher
82
+ - The length of each bar indicates the strength of the feature's impact
83
+ """)
84
+
85
+ # Footer
86
+ st.markdown("---")
best.reg.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c26ee9bad4da71cbed2f0d14951c9c2190dd0aa38f8ce5ea1a958deca783b193
3
+ size 15738433
micro_world_139countries.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:98ee1367d02f92b04d0933584a4620516b90ed5f9c554f867fa5037f3f721f7a
3
+ size 40174289
model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d6b19da76907416fb6f5ddbfd53d2fcf4b13750fb06085a849548fc9fdaf4260
3
+ size 649
model_best.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5b74d7f67e3cebb5a921fd0e7bb84350f3e34ef31932ec2022c4f91d5cec95dc
3
+ size 199835
model_xgb.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a5c6b831025998da9aec179e66d952943e387e890bb3a0cbd2696d4cb9c9df5c
3
+ size 460166
requirements.txt ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ numpy
2
+ streamlit
3
+ pandas
4
+ altair
5
+ matplotlib
6
+ seaborn
7
+ scipy
8
+ joblib
9
+ xgboost
10
+ shap
11
+ streamlit_shap
scaler.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:81342eb8c5ddbf89d9b2b7e14d5e3c3ae0c0adb8d85c6332b78c139983c13a5e
3
+ size 1047