chargesapp / app.py
abdouramandalil's picture
Create app.py
6146e09 verified
raw
history blame
1.05 kB
#Import libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pickle
import streamlit as st
#Charger le modele enregistre
@st.cache_resource
def load_model():
with open("model.pkl","rb") as file:
model = pickle.load(file)
return model
model = load_model()
#Interface utilisateur
st.title('Prediction des charges medicales')
st.write('remplissez les informations ci-dessous pour estimer les charges')
#Entrees utilisateur
age = st.slider('Age',18,100,30)
sex = st.selectbox('Sexe',['Homme','Femme'])
bmi = st.number_input('Indice de masse corporelle (IMC)',10.0,50.0,25.0)
children = st.number_input('Nombre d enfants',0,10,0)
fumeur = st.selectbox('Fumeur?',['Oui','Non'])
#Transformation des donnees
sex = 1 if sex =='Homme' else 0
fumeur = 1 if fumeur =='Oui' else 0
#Prediction
if st.button('Predire'):
input_data = np.array([[age,sex,bmi,children,fumeur]])
prediction = model.predict(input_data)[0]
st.success(f"charges medicales estimee:{prediction:.2f} $")