Lachin commited on
Commit
d92a8b5
·
1 Parent(s): 12764a9

predictions added

Browse files
Files changed (1) hide show
  1. app.py +74 -2
app.py CHANGED
@@ -3,11 +3,11 @@ import streamlit as st
3
  import matplotlib.pyplot as plt
4
  import pandas as pd
5
  import seaborn as sns
 
6
 
7
 
8
 
9
  # Title
10
- # Hi
11
  st.title("Insurance Cost Predictor")
12
 
13
  # Reading the image
@@ -114,4 +114,76 @@ col1, col2 = st.columns(2)
114
  with col1:
115
  children()
116
  with col2:
117
- scatterplot1()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  import matplotlib.pyplot as plt
4
  import pandas as pd
5
  import seaborn as sns
6
+ import pickle
7
 
8
 
9
 
10
  # Title
 
11
  st.title("Insurance Cost Predictor")
12
 
13
  # Reading the image
 
114
  with col1:
115
  children()
116
  with col2:
117
+ scatterplot1()
118
+
119
+
120
+ #user input
121
+
122
+ # function to find BMI value
123
+ def bmi(height,weight):
124
+ h=height/100
125
+ bmi_value = weight/(h**2)
126
+ return bmi_value
127
+
128
+ #Getting user input
129
+ def user_inputs():
130
+
131
+ #header
132
+ st.header("User Dashboard")
133
+
134
+ #Dashboard elements
135
+ age = st.slider('Your Age',1,100,30)
136
+ sex = st.selectbox('Select Your Gender',['male','female'])
137
+ height = st.slider('Your Height in (cm)',50,250,150)
138
+ weight = st.slider('Your Weight in (Kg)',10,150,50)
139
+ children = st.selectbox('Number of Childrens in Your Family',[0,1,2,3,4,5])
140
+ smoker = st.radio('Smoker', ['yes','no'])
141
+ region = st.radio('Select Your Region',['northeast','northwest','southeast','southwest'])
142
+
143
+ #reading user data as a dictionary
144
+ bmi1 = bmi(height, weight)
145
+ input_data={
146
+ 'age':age,
147
+ 'sex':sex,
148
+ 'bmi':bmi1,
149
+ 'children':children,
150
+ 'smoker':smoker,
151
+ 'region':region
152
+ }
153
+
154
+ #getting the copy of original data
155
+ df = data.copy()
156
+ #drop the predicting colmn
157
+ df.drop('charges', axis=1, inplace=True)
158
+ #input data as dataframe
159
+ user_data = pd.DataFrame(input_data, index=[0])
160
+ #concatenate original dataframe and user input dataframe
161
+ user_df = pd.concat([df,user_data],ignore_index=True, axis=0)
162
+ #getting dummies(categorical varaibles encoding)
163
+ user_dum_data = pd.get_dummies(user_df, columns=['sex','children','smoker','region'], drop_first=True)
164
+ #selecting the last row which is the user inputs
165
+ user_input_data = user_dum_data.iloc[-1,:]
166
+ #reading the user input data as a dataframe
167
+ final_user_data = pd.DataFrame([user_input_data.array], columns=user_dum_data.columns)
168
+ #user data
169
+ st.subheader("User Data")
170
+ st.dataframe(final_user_data)
171
+ #returning data
172
+ return final_user_data
173
+
174
+ user_results = user_inputs()
175
+
176
+ #Cost predictions
177
+
178
+ #loading the model
179
+ model = pickle.load(open("insurance_predict.pkl",'rb'))
180
+ #predicting the results
181
+ results = list(model.predict(user_results))
182
+
183
+ #setting the accuarcies, predictions
184
+ st.subheader("Predictions and Accuracies")
185
+ col3,col4 = st.columns(2)
186
+ with col3:
187
+ st.metric("Insurance cost", str(results[0]))
188
+ with col4:
189
+ st.metric("RMSE of the model", 4674.719889567355)