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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from streamlit_option_menu import option_menu
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import pickle
|
| 5 |
+
import lime
|
| 6 |
+
import lime.lime_tabular
|
| 7 |
+
import streamlit.components.v1 as components
|
| 8 |
+
from PIL import Image
|
| 9 |
+
import seaborn as sns
|
| 10 |
+
import matplotlib.pyplot as plt
|
| 11 |
+
from datetime import datetime
|
| 12 |
+
|
| 13 |
+
# 1=sidebar menu, 2=horizontal menu, 3=horizontal menu w/ custom menu
|
| 14 |
+
EXAMPLE_NO = 3
|
| 15 |
+
st.set_page_config(layout='wide')
|
| 16 |
+
st.markdown("""
|
| 17 |
+
<style>
|
| 18 |
+
.block-container {
|
| 19 |
+
padding-top: 4rem;
|
| 20 |
+
padding-bottom: 0rem;
|
| 21 |
+
padding-left: 4rem;
|
| 22 |
+
padding-right: 4rem;
|
| 23 |
+
}
|
| 24 |
+
</style>
|
| 25 |
+
""", unsafe_allow_html=True)
|
| 26 |
+
|
| 27 |
+
def streamlit_menu(example=1):
|
| 28 |
+
if example == 1:
|
| 29 |
+
# 1. as sidebar menu
|
| 30 |
+
with st.sidebar:
|
| 31 |
+
selected = option_menu(
|
| 32 |
+
menu_title="Main Menu", # required
|
| 33 |
+
options=["Acceuil", "Statistique", "Prédiction", "Suivi"], # required
|
| 34 |
+
icons=["house", "book", "envelope", "clipboard-data"], # optional
|
| 35 |
+
menu_icon="cast", # optional
|
| 36 |
+
default_index=0, # optional
|
| 37 |
+
)
|
| 38 |
+
return selected
|
| 39 |
+
|
| 40 |
+
if example == 2:
|
| 41 |
+
# 2. horizontal menu w/o custom style
|
| 42 |
+
selected = option_menu(
|
| 43 |
+
menu_title=None, # required
|
| 44 |
+
options=["Acceuil", "Statistique", "Prédiction", "Suivi"], # required
|
| 45 |
+
icons=["house", "bar-chart", "activity", "clipboard"], # optional
|
| 46 |
+
menu_icon="cast", # optional
|
| 47 |
+
default_index=0, # optional
|
| 48 |
+
orientation="horizontal",
|
| 49 |
+
)
|
| 50 |
+
return selected
|
| 51 |
+
|
| 52 |
+
if example == 3:
|
| 53 |
+
# 2. horizontal menu with custom style
|
| 54 |
+
selected = option_menu(
|
| 55 |
+
menu_title=None, # required
|
| 56 |
+
options=["Acceuil", "Statistique", "Prédiction", "Suivi"], # required
|
| 57 |
+
icons=["house", "bar-chart", "activity", "clipboard"], # optional
|
| 58 |
+
menu_icon="cast", # optional
|
| 59 |
+
default_index=0, # optional
|
| 60 |
+
orientation="horizontal",
|
| 61 |
+
styles={
|
| 62 |
+
"container": {"padding": "0!important", "background-color": "#fafafa"},
|
| 63 |
+
"icon": {"color": "orange", "font-size": "25px"},
|
| 64 |
+
"nav-link": {
|
| 65 |
+
"font-size": "25px",
|
| 66 |
+
"text-align": "left",
|
| 67 |
+
"margin": "0px",
|
| 68 |
+
"--hover-color": "#eee",
|
| 69 |
+
},
|
| 70 |
+
"nav-link-selected": {"background-color": "skyblue"},
|
| 71 |
+
},
|
| 72 |
+
)
|
| 73 |
+
return selected
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
selected = streamlit_menu(example=EXAMPLE_NO)
|
| 77 |
+
|
| 78 |
+
if selected == "Prédiction":
|
| 79 |
+
# st.title(f"You have selected {selected}")
|
| 80 |
+
# Load your trained model
|
| 81 |
+
with open('model.pkl', 'rb') as file:
|
| 82 |
+
model = pickle.load(file)
|
| 83 |
+
|
| 84 |
+
obesity_mapping = {
|
| 85 |
+
0: 'Normal',
|
| 86 |
+
1: 'Surpoid\Obése'
|
| 87 |
+
}
|
| 88 |
+
# Define the input features for the user to input
|
| 89 |
+
def user_input_features():
|
| 90 |
+
age = st.number_input('Age:',min_value=8, max_value=19, value=19, step=1, format="%d")
|
| 91 |
+
classe = st.radio('Classe_', ('Primaire','Secondaire'))
|
| 92 |
+
Zone = st.radio('zone', ('Rurale', 'Urbaine'))
|
| 93 |
+
Voler = st.radio('Voler', ('Oui', 'Non'))
|
| 94 |
+
Diversité = st.radio('Diversité', ('Mauvaise', 'Bonne'))
|
| 95 |
+
Region = st.selectbox(
|
| 96 |
+
'Region de ',
|
| 97 |
+
('Nord_ouest' ,'Sud_ouest', 'Ouest')
|
| 98 |
+
)
|
| 99 |
+
Source_eau=st.selectbox(
|
| 100 |
+
'Provenence ',
|
| 101 |
+
('Camwater','Eau_de_surface','forage','Puits','Eau_minérale')
|
| 102 |
+
)
|
| 103 |
+
Sexe = st.radio('Genre', ('F', 'M'))
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
Zone = 1 if Zone == 'Rurale' else 0
|
| 107 |
+
classe = 1 if classe == 'Primaire' else 0
|
| 108 |
+
Diversité = 1 if Diversité == 'Mauvaise' else 0
|
| 109 |
+
Region = ['Nord_ouest' ,'Sud_ouest', 'Ouest'].index(Region)
|
| 110 |
+
Source_eau=['Camwater','Eau_de_surface','forage','Puits','Eau_minérale'].index(Source_eau)
|
| 111 |
+
sex_f = 1 if Sexe == 'F' else 0
|
| 112 |
+
sex_m = 1 if Sexe == 'M' else 0
|
| 113 |
+
|
| 114 |
+
data = {
|
| 115 |
+
'Region': Region,
|
| 116 |
+
'Zone': Zone,
|
| 117 |
+
'Classe': classe,
|
| 118 |
+
'Age': age,
|
| 119 |
+
'Diversité': Diversité,
|
| 120 |
+
'Voler': Voler,
|
| 121 |
+
'Source_eau':Source_eau,
|
| 122 |
+
'Genre_F': sex_f,
|
| 123 |
+
'Genre_M': sex_m
|
| 124 |
+
}
|
| 125 |
+
features = pd.DataFrame(data, index=[0])
|
| 126 |
+
return features
|
| 127 |
+
|
| 128 |
+
# st.title('Obesity App')
|
| 129 |
+
|
| 130 |
+
# Display the input fields
|
| 131 |
+
input_df = user_input_features()
|
| 132 |
+
# Convertir toutes les colonnes non numériques en numérique si possible
|
| 133 |
+
input_df = input_df.apply(pd.to_numeric, errors='coerce')
|
| 134 |
+
|
| 135 |
+
# Remplacer les NaN par une valeur arbitraire (par exemple 0) si nécessaire
|
| 136 |
+
input_df = input_df.fillna(0)
|
| 137 |
+
|
| 138 |
+
# Initialiser LIME
|
| 139 |
+
explainer = lime.lime_tabular.LimeTabularExplainer(
|
| 140 |
+
training_data=input_df.values, # Entraînement sur la base des données d'entrée
|
| 141 |
+
feature_names=input_df.columns,
|
| 142 |
+
class_names=[obesity_mapping[0], obesity_mapping[1]],
|
| 143 |
+
mode='classification'
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
+
# Predict button
|
| 147 |
+
if st.button('Predict'):
|
| 148 |
+
# Make a prediction
|
| 149 |
+
prediction = model.predict(input_df)
|
| 150 |
+
prediction_proba = model.predict_proba(input_df)[0]
|
| 151 |
+
|
| 152 |
+
data = {
|
| 153 |
+
'Statut nutritionnel': [obesity_mapping[i] for i in range(len(prediction_proba))],
|
| 154 |
+
'Probabilité': prediction_proba
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
# Create a dataframe to display the results
|
| 158 |
+
result_df = pd.DataFrame(data)
|
| 159 |
+
|
| 160 |
+
# Transpose the dataframe to have obesity types as columns and add a row header
|
| 161 |
+
result_df = result_df.T
|
| 162 |
+
result_df.columns = result_df.iloc[0]
|
| 163 |
+
result_df = result_df.drop(result_df.index[0])
|
| 164 |
+
result_df.index = ['Probability']
|
| 165 |
+
|
| 166 |
+
# Display the results in a table with proper formatting
|
| 167 |
+
st.table(result_df.style.format("{:.4f}"))
|
| 168 |
+
# Générer l'explication LIME pour l'individu
|
| 169 |
+
# exp = explainer.explain_instance(input_df.values[0], model.predict_proba, num_features=5)
|
| 170 |
+
|
| 171 |
+
# # Afficher les explications dans Streamlit
|
| 172 |
+
# st.subheader('Explication LIME')
|
| 173 |
+
# exp.show_in_notebook(show_table=True, show_all=False)
|
| 174 |
+
# st.write(exp.as_list())
|
| 175 |
+
# Générer l'explication LIME pour l'individu
|
| 176 |
+
exp = explainer.explain_instance(input_df.values[0], model.predict_proba, num_features=4)
|
| 177 |
+
|
| 178 |
+
# Récupérer l'explication LIME sous forme HTML
|
| 179 |
+
explanation_html = exp.as_html()
|
| 180 |
+
|
| 181 |
+
# Afficher l'explication LIME dans Streamlit
|
| 182 |
+
st.subheader('Explication LIME')
|
| 183 |
+
|
| 184 |
+
# Utiliser Streamlit pour afficher du HTML
|
| 185 |
+
components.html(explanation_html, height=800) # Ajuster la hauteur selon le contenu
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
if selected == "Acceuil":
|
| 190 |
+
avant_propos = """
|
| 191 |
+
<div style="background-color: white; padding: 20px; border-radius: 10px;
|
| 192 |
+
display: flex; justify-content: center; align-items: center;
|
| 193 |
+
width: 800px; height: auto; margin: auto; flex-direction: column;
|
| 194 |
+
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);">
|
| 195 |
+
<h2 style="color: blue; text-align: center; font-size: 24px;">Avant-propos</h2>
|
| 196 |
+
<p style="color: blue; text-align: center; font-size: 16px;">
|
| 197 |
+
L'obésité est l'une des principales préoccupations de santé publique à travers le monde, avec des répercussions notables sur la qualité de vie et les coûts des soins de santé.
|
| 198 |
+
Dans un contexte où les maladies chroniques liées à l'obésité, telles que le diabète et les maladies cardiovasculaires, continuent de croître, il est impératif de développer des outils capables de prédire et de prévenir cette condition.
|
| 199 |
+
</p>
|
| 200 |
+
<p style="color: blue; text-align: center; font-size: 16px;">
|
| 201 |
+
L'application que nous présentons ici repose sur les technologies modernes de <strong>machine learning</strong> pour prédire le risque d'obésité à partir de divers facteurs liés au mode de vie,
|
| 202 |
+
aux habitudes alimentaires et aux caractéristiques individuelles. Cette solution, développée à l'aide de <strong>Streamlit</strong>, permet non seulement d'offrir une interface intuitive et accessible,
|
| 203 |
+
mais également d'analyser rapidement et précisément les données des utilisateurs afin d'anticiper les risques associés au surpoids.
|
| 204 |
+
</p>
|
| 205 |
+
<p style="color: blue; text-align: center; font-size: 16px;">
|
| 206 |
+
L'objectif principal de cette application est de fournir une aide à la décision pour les professionnels de santé, les chercheurs, et même les utilisateurs individuels
|
| 207 |
+
qui souhaitent comprendre et gérer leur risque personnel. En quelques clics, les utilisateurs peuvent explorer les facteurs influents et recevoir des prévisions basées sur des algorithmes avancés d'apprentissage automatique.
|
| 208 |
+
</p>
|
| 209 |
+
<p style="color: blue; text-align: center; font-size: 16px;">
|
| 210 |
+
Cette application permet aussi de faire un suivi personnalisé sur l'indice de masse corporelle, precisement de
|
| 211 |
+
son statut nutritionnel.
|
| 212 |
+
</p>
|
| 213 |
+
</div>
|
| 214 |
+
"""
|
| 215 |
+
|
| 216 |
+
# Afficher le texte stylisé en bleu et centré sur un fond blanc
|
| 217 |
+
st.markdown(avant_propos, unsafe_allow_html=True)
|
| 218 |
+
# Ajouter un bouton qui redirige vers un site externe
|
| 219 |
+
url = "https://www.who.int/fr/news-room/fact-sheets/detail/obesity-and-overweight" # Remplacez par l'URL souhaitée
|
| 220 |
+
if st.button("pour plus d'informations"):
|
| 221 |
+
st.write(f"[Cliquez ici pour visiter le site]({url})")
|
| 222 |
+
if selected == "Statistique":
|
| 223 |
+
# Ouvrir l'image avec Pillow
|
| 224 |
+
#image = Image.open("az.JPEG")
|
| 225 |
+
|
| 226 |
+
# Redimensionner l'image (largeur, hauteur)
|
| 227 |
+
#image = image.resize((300, 200)) # Par exemple, 300x200 pixels
|
| 228 |
+
|
| 229 |
+
# Afficher l'image redimensionnée
|
| 230 |
+
#st.image(image, caption="Image redimensionnée", use_column_width=False)
|
| 231 |
+
# Titre de l'application
|
| 232 |
+
st.title("Visualisation des données avec Seaborn et Pandas")
|
| 233 |
+
|
| 234 |
+
# Charger le fichier CSV
|
| 235 |
+
uploaded_file = st.file_uploader("Choisissez un fichier", type=["csv", "xlsx", "json"])
|
| 236 |
+
|
| 237 |
+
if uploaded_file is not None:
|
| 238 |
+
# Lecture du fichier CSV
|
| 239 |
+
file_extension = uploaded_file.name.split('.')[-1]
|
| 240 |
+
if file_extension == 'csv':
|
| 241 |
+
# Lecture du fichier CSV
|
| 242 |
+
df = pd.read_csv(uploaded_file)
|
| 243 |
+
elif file_extension == 'xlsx':
|
| 244 |
+
# Lecture du fichier Excel
|
| 245 |
+
df = pd.read_excel(uploaded_file)
|
| 246 |
+
elif file_extension == 'json':
|
| 247 |
+
# Lecture du fichier JSON
|
| 248 |
+
df = pd.read_json(uploaded_file)
|
| 249 |
+
else:
|
| 250 |
+
st.error("Format de fichier non supporté!")
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
# Afficher le dataframe
|
| 254 |
+
st.write("Aperçu du dataset :")
|
| 255 |
+
st.write(df.head())
|
| 256 |
+
|
| 257 |
+
# Afficher les statistiques descriptives
|
| 258 |
+
st.write("Statistiques descriptives :")
|
| 259 |
+
st.write(df.describe())
|
| 260 |
+
|
| 261 |
+
# Sélection des variables pour les visualisations
|
| 262 |
+
numerical_columns = df.select_dtypes(include=['float64', 'int64']).columns.tolist()
|
| 263 |
+
categorical_columns = df.select_dtypes(include=['object', 'category']).columns.tolist()
|
| 264 |
+
|
| 265 |
+
# Distribution d'une variable
|
| 266 |
+
st.subheader("Distribution d'une variable numérique")
|
| 267 |
+
selected_column = st.selectbox("Choisissez une variable numérique", numerical_columns)
|
| 268 |
+
if st.button("Afficher la distribution"):
|
| 269 |
+
fig, ax = plt.subplots(figsize=(5, 6))
|
| 270 |
+
sns.histplot(df[selected_column], kde=True, ax=ax)
|
| 271 |
+
st.pyplot(fig)
|
| 272 |
+
|
| 273 |
+
# Scatter plot
|
| 274 |
+
st.subheader("Scatter Plot entre deux variables numériques")
|
| 275 |
+
x_axis = st.selectbox("Choisissez la variable pour l'axe X", numerical_columns)
|
| 276 |
+
y_axis = st.selectbox("Choisissez la variable pour l'axe Y", numerical_columns, key='scatter')
|
| 277 |
+
if st.button("Afficher le scatter plot"):
|
| 278 |
+
fig, ax = plt.subplots(figsize=(8, 4))
|
| 279 |
+
sns.scatterplot(x=df[x_axis], y=df[y_axis], ax=ax)
|
| 280 |
+
st.pyplot(fig)
|
| 281 |
+
|
| 282 |
+
# Boxplot
|
| 283 |
+
st.subheader("Boxplot d'une variable numérique par rapport à une variable catégorielle")
|
| 284 |
+
selected_categorical = st.selectbox("Choisissez une variable catégorielle", categorical_columns)
|
| 285 |
+
selected_numerical = st.selectbox("Choisissez une variable numérique", numerical_columns, key='boxplot')
|
| 286 |
+
if st.button("Afficher le boxplot"):
|
| 287 |
+
fig, ax = plt.subplots(figsize=(8, 4))
|
| 288 |
+
sns.boxplot(x=df[selected_categorical], y=df[selected_numerical], ax=ax)
|
| 289 |
+
st.pyplot(fig)
|
| 290 |
+
|
| 291 |
+
if selected == "Suivi":
|
| 292 |
+
# Charger ou initialiser les données de suivi
|
| 293 |
+
def load_data():
|
| 294 |
+
try:
|
| 295 |
+
data = pd.read_csv('imc_data.csv')
|
| 296 |
+
except FileNotFoundError:
|
| 297 |
+
data = pd.DataFrame(columns=['Date', 'Weight', 'Height', 'BMI', 'Status'])
|
| 298 |
+
return data
|
| 299 |
+
|
| 300 |
+
def save_data(data):
|
| 301 |
+
data.to_csv('imc_data.csv', index=False)
|
| 302 |
+
|
| 303 |
+
# Calculer l'IMC et le statut nutritionnel
|
| 304 |
+
def calculate_bmi(weight, height):
|
| 305 |
+
return weight / (height ** 2)
|
| 306 |
+
|
| 307 |
+
def get_nutritional_status(bmi):
|
| 308 |
+
if bmi < 18.5:
|
| 309 |
+
return "Insuffisance pondérale"
|
| 310 |
+
elif 18.5 <= bmi < 25:
|
| 311 |
+
return "Poids normal"
|
| 312 |
+
elif 25 <= bmi < 30:
|
| 313 |
+
return "Surpoids"
|
| 314 |
+
else:
|
| 315 |
+
return "Obésité"
|
| 316 |
+
|
| 317 |
+
# Interface utilisateur Streamlit
|
| 318 |
+
st.title("Suivi de l'IMC et du Statut Nutritionnel")
|
| 319 |
+
|
| 320 |
+
# Collecte des données utilisateur
|
| 321 |
+
weight = st.number_input("Poids (en kg)", min_value=30.0, max_value=200.0, value=70.0)
|
| 322 |
+
height = st.number_input("Taille (en mètres)", min_value=1.0, max_value=2.5, value=1.75)
|
| 323 |
+
|
| 324 |
+
# Calculer l'IMC et le statut nutritionnel
|
| 325 |
+
if height > 0:
|
| 326 |
+
bmi = calculate_bmi(weight, height)
|
| 327 |
+
status = get_nutritional_status(bmi)
|
| 328 |
+
st.write(f"Votre IMC est : {bmi:.2f}")
|
| 329 |
+
st.write(f"Statut nutritionnel : {status}")
|
| 330 |
+
|
| 331 |
+
# Charger et mettre à jour les données de suivi
|
| 332 |
+
data = load_data()
|
| 333 |
+
if st.button("Enregistrer vos données"):
|
| 334 |
+
new_entry = pd.DataFrame({
|
| 335 |
+
'Date': [datetime.now().strftime("%Y-%m-%d %H:%M:%S")],
|
| 336 |
+
'Weight': [weight],
|
| 337 |
+
'Height': [height],
|
| 338 |
+
'BMI': [bmi],
|
| 339 |
+
'Status': [status]
|
| 340 |
+
})
|
| 341 |
+
data = pd.concat([data, new_entry], ignore_index=True)
|
| 342 |
+
save_data(data)
|
| 343 |
+
st.success("Vos données ont été enregistrées avec succès !")
|
| 344 |
+
|
| 345 |
+
# Afficher l'évolution de l'IMC
|
| 346 |
+
if not data.empty:
|
| 347 |
+
st.subheader("Évolution de votre IMC")
|
| 348 |
+
data['Date'] = pd.to_datetime(data['Date'])
|
| 349 |
+
plt.figure(figsize=(10, 6))
|
| 350 |
+
plt.plot(data['Date'], data['BMI'], marker='o')
|
| 351 |
+
plt.title("Évolution de l'IMC")
|
| 352 |
+
plt.xlabel("Date")
|
| 353 |
+
plt.ylabel("IMC")
|
| 354 |
+
plt.grid(True)
|
| 355 |
+
st.pyplot(plt)
|
| 356 |
+
|
| 357 |
+
# Afficher l'historique des données soumises
|
| 358 |
+
st.subheader("Historique des données soumises")
|
| 359 |
+
st.dataframe(data[['Date', 'Weight', 'Height', 'BMI', 'Status']])
|
| 360 |
+
else:
|
| 361 |
+
st.warning("Veuillez entrer une taille valide pour calculer l'IMC.")
|
model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:28aa471b6ae23de5abe249cfe72e5bfe8240d72e942feeacb56980d1aed7020c
|
| 3 |
+
size 335533
|
requirements.txt.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit==1.25.0
|
| 2 |
+
streamlit-option-menu==0.3.2
|
| 3 |
+
pandas==2.1.1
|
| 4 |
+
pickle5==0.0.12
|
| 5 |
+
lime==0.2.0.1
|
| 6 |
+
Pillow==9.2.0
|
| 7 |
+
seaborn==0.12.2
|
| 8 |
+
matplotlib==3.7.1
|