Loki-07 commited on
Commit
e1b1006
·
verified ·
1 Parent(s): 24e8500

Upload 4 files

Browse files
Files changed (4) hide show
  1. Best_model.joblib +3 -0
  2. Medical_insurance.csv +0 -0
  3. app.py +102 -0
  4. requirements.txt +6 -0
Best_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d0ec09e35995ba662ab7c7653bb1ece1fb98cddccf8e1e75d14e506f1d3b63a2
3
+ size 12494689
Medical_insurance.csv ADDED
The diff for this file is too large to render. See raw diff
 
app.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from sklearn.ensemble import GradientBoostingRegressor
3
+ import joblib
4
+
5
+ model_path = 'Best_model.joblib'
6
+ loaded_model = joblib.load(model_path)
7
+
8
+
9
+ # Preprocess input function
10
+ def preprocess_input(input_data):
11
+ age = input_data['age']
12
+ bmi = input_data.get('bmi', None)
13
+ height = input_data.get('height', None)
14
+ weight = input_data.get('weight', None)
15
+ children = input_data['children']
16
+
17
+ # Convert height to meters based on the selected unit
18
+ height_unit = input_data.get('height_unit', 'meters')
19
+ if height is not None and height_unit != 'meters':
20
+ if height_unit == 'centimeters':
21
+ height /= 100
22
+ elif height_unit == 'feet':
23
+ height *= 0.3048 # 1 foot = 0.3048 meters
24
+
25
+ # Calculate BMI if height and weight are provided and height is not zero
26
+ if height is not None and height != 0 and weight is not None:
27
+ bmi = weight / (height ** 2)
28
+
29
+ # Convert sex to binary representation
30
+ sex_0 = 1 if input_data['sex'] == 'female' else 0
31
+ sex_1 = 1 - sex_0
32
+
33
+ # Convert smoker to binary representation
34
+ smoker_0 = 1 if input_data['smoker'] == 'no' else 0
35
+ smoker_1 = 1 - smoker_0
36
+
37
+ # Map region name to numerical representation
38
+ region_mapping = {'southeast': 1, 'southwest': 2, 'northwest': 3, 'northeast': 4}
39
+ region = region_mapping.get(input_data['region'], 0)
40
+
41
+ # Create binary representations for each region
42
+ region_1 = 1 if region == 1 else 0
43
+ region_2 = 1 if region == 2 else 0
44
+ region_3 = 1 if region == 3 else 0
45
+ region_4 = 1 if region == 4 else 0
46
+
47
+ # Create the formatted input list with 11 features
48
+ formatted_input = [age, bmi, children, sex_0, sex_1, region_1, region_2, region_3, region_4, smoker_0, smoker_1]
49
+
50
+ return formatted_input
51
+
52
+
53
+ # Input page
54
+ def input_page():
55
+ st.title('Health Insurance Price Prediction')
56
+ st.write('Please fill in the following details:')
57
+ age = st.number_input('Age', min_value=0, step=1)
58
+ sex = st.radio('Sex', ('male', 'female'))
59
+
60
+ # Side-by-side input for height unit and height
61
+ col1, col2 = st.columns(2)
62
+ with col1:
63
+ height_unit = st.selectbox('Height Unit', ('meters', 'centimeters', 'feet'))
64
+ with col2:
65
+ height = st.number_input('Height', min_value=0.0, step=0.01)
66
+ weight = st.number_input('Weight (in kg)', min_value=0.0, step=0.1)
67
+
68
+ # Calculate BMI immediately after entering height and weight if height is not zero
69
+ bmi = None
70
+ if height is not None and height != 0.0 and weight is not None:
71
+ # Convert height based on selected height unit
72
+ if height_unit != 'meters':
73
+ if height_unit == 'centimeters':
74
+ height /= 100
75
+ elif height_unit == 'feet':
76
+ height *= 0.3048 # 1 foot = 0.3048 meters
77
+
78
+ # Calculate BMI
79
+ bmi = weight / (height ** 2)
80
+ st.write(f'BMI: {bmi:.2f}')
81
+
82
+ children = st.number_input('Number of Children', min_value=0, step=1)
83
+ smoker = st.selectbox('Smoker', ('yes', 'no'))
84
+ region = st.selectbox('Region', ('southeast', 'southwest', 'northwest', 'northeast'))
85
+
86
+ if st.button('Predict'):
87
+ input_data = {'age': age, 'sex': sex, 'height': height, 'weight': weight, 'children': children,
88
+ 'smoker': smoker, 'region': region, 'bmi': bmi, 'height_unit': height_unit}
89
+ processed_input = preprocess_input(input_data)
90
+ charges = loaded_model.predict([processed_input])[0]
91
+ st.write('## Estimated Charges')
92
+ st.write(f'Estimated Charges: ${charges:.2f}', unsafe_allow_html=True)
93
+ st.write('The following value is estimated based on historical data and predictive modeling techniques and may not represent the exact amount.')
94
+
95
+
96
+ # Main function
97
+ def main():
98
+ input_page()
99
+
100
+
101
+ if __name__ == '__main__':
102
+ main()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ streamlit
2
+ scikit-learn
3
+ pandas
4
+ numpy
5
+ matplotlib
6
+ joblib