hackerbyhobby commited on
Commit
e4a6aba
·
unverified ·
1 Parent(s): 0d76b3a

updated app

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py CHANGED
@@ -48,6 +48,40 @@ def predict_heart_failure(age_category, alcohol_drinkers, chest_scan, covid_posi
48
  print(f"Prediction: {prediction}")
49
  return "High likelihood of heart failure" if prediction == 1 else "Low likelihood of heart failure"
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  # Define Gradio inputs
52
  gradio_inputs = [
53
  gr.Radio(
 
48
  print(f"Prediction: {prediction}")
49
  return "High likelihood of heart failure" if prediction == 1 else "Low likelihood of heart failure"
50
 
51
+ def predict_heart_failure(age_category, alcohol_drinkers, chest_scan, covid_positive, physical_health_days, mental_health_days, sleep_hours, bmi):
52
+ # Prepare input data
53
+ input_data = {feature: 0 for feature in feature_names}
54
+ input_data[f"AgeCategory_{age_category}"] = 1
55
+ input_data[f"AlcoholDrinkers_{alcohol_drinkers}"] = 1
56
+ input_data[f"ChestScan_{chest_scan}"] = 1
57
+ input_data[f"CovidPos_{covid_positive}"] = 1
58
+ input_data["PhysicalHealthDays"] = physical_health_days
59
+ input_data["MentalHealthDays"] = mental_health_days
60
+ input_data["SleepHours"] = sleep_hours
61
+ input_data["BMI"] = bmi
62
+
63
+ # Convert to DataFrame
64
+ input_df = pd.DataFrame([input_data])
65
+
66
+ # Debugging: Print the input DataFrame
67
+ print("Input DataFrame passed to the model:")
68
+ print(input_df)
69
+
70
+ # Predict probabilities
71
+ probs = model.predict_proba(input_df)
72
+ print("Predicted probabilities:")
73
+ print(probs)
74
+
75
+ # Adjust threshold and make predictions
76
+ threshold = 0.4
77
+ predictions = (probs[:, 1] >= threshold).astype(int)
78
+ print("Predictions with adjusted threshold:")
79
+ print(predictions)
80
+
81
+ # Return prediction
82
+ return "High likelihood of heart failure" if predictions[0] == 1 else "Low likelihood of heart failure"
83
+
84
+
85
  # Define Gradio inputs
86
  gradio_inputs = [
87
  gr.Radio(