Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,29 +7,31 @@ model = joblib.load("best_random_forest_model.pkl")
|
|
| 7 |
|
| 8 |
# Define the prediction function
|
| 9 |
def predict_alzheimers(
|
| 10 |
-
age, gender, bmi,
|
| 11 |
-
|
| 12 |
-
cognitive_score, depression,
|
| 13 |
genetic_risk, social_engagement, income, stress
|
| 14 |
):
|
| 15 |
-
#
|
| 16 |
-
gender = 1 if gender == "
|
| 17 |
-
physical_activity = {"Low": 0, "Medium": 1, "High": 2}[physical_activity]
|
| 18 |
-
smoking = {"Never": 0, "Former": 1, "Current": 2}[smoking]
|
| 19 |
-
alcohol = {"Never": 0, "Occasionally": 1, "Regularly": 2}[alcohol]
|
| 20 |
diabetes = 1 if diabetes == "Yes" else 0
|
| 21 |
hypertension = 1 if hypertension == "Yes" else 0
|
| 22 |
-
cholesterol = {"Low": 0, "Normal": 1, "High": 2}.get(cholesterol, 1) # default: Normal
|
| 23 |
-
|
| 24 |
family_history = 1 if family_history == "Yes" else 0
|
| 25 |
-
depression = {"Low": 0, "Medium": 1, "High": 2}[depression]
|
| 26 |
-
sleep_quality = {"Poor": 0, "Average": 1, "Good": 2}[sleep_quality]
|
| 27 |
-
dietary = {"Healthy": 0, "Average": 1, "Unhealthy": 2}.get(dietary, 1) # default: Average
|
| 28 |
-
|
| 29 |
genetic_risk = 1 if genetic_risk == "Yes" else 0
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
# Create input array
|
| 35 |
features = np.array([[
|
|
|
|
| 7 |
|
| 8 |
# Define the prediction function
|
| 9 |
def predict_alzheimers(
|
| 10 |
+
age, gender, bmi, diabetes, hypertension, cholesterol,
|
| 11 |
+
physical_activity, smoking, alcohol, family_history,
|
| 12 |
+
cognitive_score, depression, sleep, dietary,
|
| 13 |
genetic_risk, social_engagement, income, stress
|
| 14 |
):
|
| 15 |
+
# Map categorical values to numerical ones
|
| 16 |
+
gender = 1 if gender == "Male" else 0
|
|
|
|
|
|
|
|
|
|
| 17 |
diabetes = 1 if diabetes == "Yes" else 0
|
| 18 |
hypertension = 1 if hypertension == "Yes" else 0
|
|
|
|
|
|
|
| 19 |
family_history = 1 if family_history == "Yes" else 0
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
genetic_risk = 1 if genetic_risk == "Yes" else 0
|
| 21 |
+
|
| 22 |
+
cholesterol = {"Low": 0, "Normal": 1, "High": 2}.get(cholesterol, 1)
|
| 23 |
+
physical_activity = {"Low": 0, "Medium": 1, "High": 2}.get(physical_activity, 1)
|
| 24 |
+
smoking = {"Never": 0, "Former": 1, "Current": 2}.get(smoking, 1)
|
| 25 |
+
alcohol = {"Never": 0, "Occasionally": 1, "Regularly": 2}.get(alcohol, 1)
|
| 26 |
+
depression = {"Low": 0, "Medium": 1, "High": 2}.get(depression, 1)
|
| 27 |
+
sleep = {"Poor": 0, "Average": 1, "Good": 2}.get(sleep, 1)
|
| 28 |
+
dietary = {"Healthy": 0, "Average": 1, "Unhealthy": 2}.get(dietary, 1)
|
| 29 |
+
social_engagement = {"Low": 0, "Medium": 1, "High": 2}.get(social_engagement, 1)
|
| 30 |
+
income = {"Low": 0, "Medium": 1, "High": 2}.get(income, 1)
|
| 31 |
+
stress = {"Low": 0, "Medium": 1, "High": 2}.get(stress, 1)
|
| 32 |
+
|
| 33 |
+
# ... your model input code continues ...
|
| 34 |
+
|
| 35 |
|
| 36 |
# Create input array
|
| 37 |
features = np.array([[
|