Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#Import libraries
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
import seaborn as sns
|
6 |
+
import pickle
|
7 |
+
import streamlit as st
|
8 |
+
|
9 |
+
#Charger le modele enregistre
|
10 |
+
@st.cache_resource
|
11 |
+
def load_model():
|
12 |
+
with open("model.pkl","rb") as file:
|
13 |
+
model = pickle.load(file)
|
14 |
+
return model
|
15 |
+
model = load_model()
|
16 |
+
|
17 |
+
#Interface utilisateur
|
18 |
+
st.title('Prediction des charges medicales')
|
19 |
+
st.write('remplissez les informations ci-dessous pour estimer les charges')
|
20 |
+
|
21 |
+
#Entrees utilisateur
|
22 |
+
age = st.slider('Age',18,100,30)
|
23 |
+
sex = st.selectbox('Sexe',['Homme','Femme'])
|
24 |
+
bmi = st.number_input('Indice de masse corporelle (IMC)',10.0,50.0,25.0)
|
25 |
+
children = st.number_input('Nombre d enfants',0,10,0)
|
26 |
+
fumeur = st.selectbox('Fumeur?',['Oui','Non'])
|
27 |
+
|
28 |
+
#Transformation des donnees
|
29 |
+
sex = 1 if sex =='Homme' else 0
|
30 |
+
fumeur = 1 if fumeur =='Oui' else 0
|
31 |
+
|
32 |
+
#Prediction
|
33 |
+
if st.button('Predire'):
|
34 |
+
input_data = np.array([[age,sex,bmi,children,fumeur]])
|
35 |
+
prediction = model.predict(input_data)[0]
|
36 |
+
st.success(f"charges medicales estimee:{prediction:.2f} $")
|