SerenaTOUM commited on
Commit
0b4d87f
·
verified ·
1 Parent(s): 9eb651c

Create adolescente.py

Browse files
Files changed (1) hide show
  1. adolescente.py +84 -0
adolescente.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ from joblib import load
4
+
5
+ def load_model():
6
+ model_path = "model.joblib"
7
+ try:
8
+ model = load(model_path)
9
+ return model
10
+ except FileNotFoundError:
11
+ st.error("Le fichier du modèle n'a pas été trouvé.")
12
+ return None
13
+
14
+ def show():
15
+ st.title("Prédiction d'Anémie")
16
+
17
+ # Chargement du modèle
18
+ model = load_model()
19
+ if model is None:
20
+ return
21
+
22
+ # Saisie des données
23
+ age = st.number_input("Âge", min_value=10, max_value=19)
24
+ fer = st.selectbox("Avez-vous pris du fer sous quelque forme que ce soit au cours des 3 derniers mois ?", ["Oui", "Non"])
25
+ poids = st.number_input("Poids (en Kg)", min_value=10.0)
26
+ taille = st.number_input("Taille (en cm)", min_value=50.0)
27
+
28
+ # Calcul de l'IMC
29
+ if poids > 0 and taille > 0:
30
+ taille_m = taille / 100
31
+ imc = poids / (taille_m ** 2)
32
+ else:
33
+ imc = 0
34
+
35
+ # Affichage de l'IMC
36
+ st.write(f"IMC Calculé: {imc:.2f}")
37
+
38
+ menstruation = st.selectbox("Voyez-vous déjà vos règles ?", ["Oui", "Non"])
39
+ statut_matrimonial = st.selectbox("Quel est votre statut matrimonial?", ["Célibataire", "Mariée"])
40
+ zone = st.selectbox("Quelle est votre zone d'habitation ?", ["Urbaine", "Rurale"])
41
+ region = st.selectbox("Quelle est la région que vous habitez", ["Adamaoua", "Est", "Extrême Nord", "Nord"])
42
+
43
+ if st.button("Faire la Prédiction"):
44
+ # Préparation des données pour la prédiction
45
+ data = {
46
+ 'Age': age,
47
+ 'Fer': 1 if fer == "Oui" else 2,
48
+ 'IMC_Calcule': imc,
49
+ 'Menstruation': 1 if menstruation == "Oui" else 2,
50
+ 'Statut_Matrimonial': 1 if statut_matrimonial == "Célibataire" else 2,
51
+ 'Zone': 0 if zone == "Urbaine" else 1,
52
+ 'Region': {"Adamaoua": 1, "Est": 2, "Extrême Nord": 3, "Nord": 4}[region],
53
+ 'Menage': 850
54
+ }
55
+
56
+ df = pd.DataFrame([data])
57
+
58
+ # Prédiction
59
+ new_data_encoded = pd.get_dummies(df, drop_first=True)
60
+ expected_columns = model.feature_names_in_
61
+ for column in expected_columns:
62
+ if column not in new_data_encoded.columns:
63
+ new_data_encoded[column] = 0
64
+ new_data_encoded = new_data_encoded[expected_columns]
65
+
66
+ prediction = model.predict(new_data_encoded)
67
+ prediction_proba = model.predict_proba(new_data_encoded)
68
+
69
+ # Stockage des résultats dans st.session_state
70
+ result_text = "Anémique" if prediction[0] == 1 else "Non Anémique"
71
+ st.session_state.data = data
72
+ st.session_state.prediction = {
73
+ 'Prediction': result_text,
74
+ 'Probability': prediction_proba[0][prediction[0]] # Probabilité à stocker pour le rapport
75
+ }
76
+ st.session_state.goto_report = True
77
+
78
+ # Affichage des résultats de la prédiction
79
+ st.markdown(f"<p style='color:red; text-align:center;'>Prédiction : {result_text}</p>", unsafe_allow_html=True)
80
+
81
+
82
+ if __name__ == '__main__':
83
+ show()
84
+