joaopimenta commited on
Commit
932aa21
ยท
verified ยท
1 Parent(s): ddebce6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -20
app.py CHANGED
@@ -32,6 +32,8 @@ import torch.nn as nn
32
  import time
33
 
34
 
 
 
35
 
36
  # Criar o menu na barra lateral
37
  st.sidebar.title("๐Ÿ“Œ Menu")
@@ -277,8 +279,7 @@ elif page== "๐Ÿ“Š Tabular Data":
277
  fixed_feature_vector = {age_group_mapping.get(k, k): v for k, v in feature_vector.items()}
278
  feature_df = pd.DataFrame([fixed_feature_vector]).reindex(columns=expected_columns, fill_value=0)
279
 
280
- #
281
- st.write(feature_df)
282
  # Predict probability of readmission
283
  prediction_proba = tabular_model.predict_proba(feature_df)[:, 1]
284
  probability = float(prediction_proba[0]) # Convert NumPy array to scalar
@@ -333,6 +334,8 @@ elif page== "๐Ÿ“Š Tabular Data":
333
  import streamlit as st
334
  import time
335
  import random
 
 
336
  # Tรญtulo estilizado
337
  st.markdown("""
338
  <h1 style='text-align: center; color: #2c3e50;'>๐Ÿฉบ AI-Powered Patient Readmission Analysis</h1>
@@ -350,36 +353,41 @@ elif page== "๐Ÿ“Š Tabular Data":
350
  time.sleep(2) # Simular carregamento
351
  try:
352
  ai_output = """
353
- To understand why the model made a certain prediction, let's analyze the feature impacts provided. The feature impacts represent the change in the predicted outcome (patient readmission) for a one-unit change in the feature, while holding all other features constant. The magnitude and direction of the impact indicate how much each feature contributes to the prediction.
354
-
355
- Key Characteristics Influencing the Prediction:
356
- Previous Stays (1.56 impact): This feature has the highest positive impact, suggesting that patients with a history of previous stays at the hospital are more likely to be readmitted. The large impact indicates that the model places significant weight on this factor, likely because repeated hospital visits can signify chronic conditions or complications that are not fully resolved.
357
-
358
- Number of Medications (n_meds) (0.17 impact): Patients taking a higher number of medications are at a higher risk of readmission. This could be due to the complexity of their medical conditions, potential side effects, or interactions between medications that may lead to further health issues.
359
 
360
- Time Since Last Stay (0.16 impact): The time elapsed since the patient's last hospital stay also positively influences the prediction of readmission. This might indicate that patients who have been discharged recently are at a higher risk of returning, possibly due to incomplete recovery or the nature of their condition requiring ongoing care.
 
361
 
362
- Real Age (0.14 impact): The patient's age is another factor that increases the likelihood of readmission. Older patients may have more complex health issues, diminished physiological reserve, and a higher likelihood of comorbid conditions, all of which can contribute to the need for repeat hospitalizations.
363
 
364
- Length of Stay (los_days) (0.07 impact): Although less influential than the top factors, a longer hospital stay during the current or previous admission(s) slightly increases the risk of readmission. This could be indicative of more severe illness, complications, or the need for prolonged recovery periods.
 
 
 
 
 
365
 
366
- Less Influential but Still Relevant Factors:
367
- CCI Score (0.05 impact): The Charlson Comorbidity Index (CCI) score, which predicts the ten-year mortality for a patient who may have a range of comorbid conditions, such as heart disease, diabetes, or cancer. A higher score indicates a higher risk of mortality and, by extension, potentially a higher risk of readmission due to the complexity of the patient's health conditions.
368
 
369
- DRG Severity (-0.04 impact): The Diagnosis-Related Group (DRG) severity, which categorizes hospital cases into one or more groups that are expected to have similar hospital resource use, has a negative impact. This suggests that higher severity cases, as categorized by DRG, might actually have a slightly lower risk of readmission, possibly due to more intensive treatment and monitoring during their initial stay.
 
 
 
 
370
 
371
- Race (race_WHITE: -0.04 impact, race_UNKNOWN: 0.03 impact): The impacts of race are relatively small and might reflect underlying socio-economic or healthcare access disparities rather than direct biological factors. However, interpreting these impacts requires caution due to the potential for confounding variables and the ethical considerations surrounding race in healthcare outcomes.
372
 
373
- Blood Cells (0.03 impact): This factor, likely referring to some measure of blood cell count or health, has a minor positive impact, suggesting that abnormalities in blood cell counts could slightly increase the risk of readmission, potentially due to underlying conditions affecting the blood or bone marrow.
 
374
 
375
- Conclusion:
376
- The model's prediction of patient readmission is most strongly influenced by the patient's history of previous hospital stays, indicating a potential for chronic or recurring health issues. The number of medications, time since the last stay, and the patient's age are also significant factors, highlighting the complexity of the patient's health condition and the potential for ongoing care needs. While other factors such as CCI score, DRG severity, race, and blood cell health play a role, their impacts are less pronounced. Understanding these factors can help healthcare providers identify high-risk patients and implement targeted interventions to reduce the likelihood of readmission.
377
  """
378
 
379
  # ๐ŸŽญ **Show AI Response in a Stylish Chat Format**
380
  with st.chat_message("assistant"):
381
- st.markdown(f"**๐Ÿ’ก AI Explanation:**\n\n{ai_output}")
382
-
383
  except Exception as e:
384
  st.error(f"โš ๏ธ Error retrieving response: {e}")
385
  st.stop()
 
32
  import time
33
 
34
 
35
+ # Defining wide mode
36
+ st.set_page_config(layout="wide")
37
 
38
  # Criar o menu na barra lateral
39
  st.sidebar.title("๐Ÿ“Œ Menu")
 
279
  fixed_feature_vector = {age_group_mapping.get(k, k): v for k, v in feature_vector.items()}
280
  feature_df = pd.DataFrame([fixed_feature_vector]).reindex(columns=expected_columns, fill_value=0)
281
 
282
+ #st.write(feature_df)
 
283
  # Predict probability of readmission
284
  prediction_proba = tabular_model.predict_proba(feature_df)[:, 1]
285
  probability = float(prediction_proba[0]) # Convert NumPy array to scalar
 
334
  import streamlit as st
335
  import time
336
  import random
337
+ from textwrap import dedent
338
+
339
  # Tรญtulo estilizado
340
  st.markdown("""
341
  <h1 style='text-align: center; color: #2c3e50;'>๐Ÿฉบ AI-Powered Patient Readmission Analysis</h1>
 
353
  time.sleep(2) # Simular carregamento
354
  try:
355
  ai_output = """
356
+ # ๐Ÿฉบ AI-Powered Patient Readmission Analysis
 
 
 
 
 
357
 
358
+ ## ๐Ÿค– Understanding the Model's Prediction
359
+ The feature impacts indicate how much each factor contributes to the model's decision to predict patient readmission. The magnitude and direction of the impact determine its importance.
360
 
361
+ ---
362
 
363
+ ## ๐Ÿ” Key Characteristics Influencing the Prediction:
364
+ - **Previous Stays** (1.56 impact): This feature has the highest positive impact, suggesting that patients with a history of previous hospital stays are more likely to be readmitted. The large impact indicates that the model places significant weight on this factor, likely because repeated hospital visits can signify chronic conditions or complications that are not fully resolved.
365
+ - **Number of Medications (n_meds)** (0.17 impact): Patients taking a higher number of medications are at a higher risk of readmission. This could be due to the complexity of their medical conditions, potential side effects, or interactions between medications that may lead to further health issues.
366
+ - **Time Since Last Stay** (0.16 impact): The time elapsed since the patient's last hospital stay also positively influences the prediction of readmission. This might indicate that patients who have been discharged recently are at a higher risk of returning, possibly due to incomplete recovery or the nature of their condition requiring ongoing care.
367
+ - **Real Age** (0.14 impact): The patient's age is another factor that increases the likelihood of readmission. Older patients may have more complex health issues, diminished physiological reserve, and a higher likelihood of comorbid conditions, all of which can contribute to the need for repeat hospitalizations.
368
+ - **Length of Stay (los_days)** (0.07 impact): Although less influential than the top factors, a longer hospital stay during the current or previous admission(s) slightly increases the risk of readmission. This could be indicative of more severe illness, complications, or the need for prolonged recovery periods.
369
 
370
+ ---
 
371
 
372
+ ## ๐Ÿ“‰ Less Influential but Still Relevant Factors:
373
+ - **CCI Score** (0.05 impact): The Charlson Comorbidity Index (CCI) score predicts the ten-year mortality for a patient with comorbid conditions such as heart disease, diabetes, or cancer. A higher score indicates a higher risk of mortality and, by extension, potentially a higher risk of readmission due to the complexity of the patient's health conditions.
374
+ - **DRG Severity** (-0.04 impact): The Diagnosis-Related Group (DRG) severity categorizes hospital cases based on expected resource use. Its negative impact suggests that higher severity cases might actually have a slightly lower risk of readmission, possibly due to more intensive treatment and monitoring during their initial stay.
375
+ - **Race** (race_WHITE: -0.04 impact, race_UNKNOWN: 0.03 impact): The impacts of race are relatively small and might reflect underlying socio-economic or healthcare access disparities rather than direct biological factors. However, interpreting these impacts requires caution due to the potential for confounding variables and the ethical considerations surrounding race in healthcare outcomes.
376
+ - **Blood Cells** (0.03 impact): This factor, likely referring to some measure of blood cell count or health, has a minor positive impact, suggesting that abnormalities in blood cell counts could slightly increase the risk of readmission, potentially due to underlying conditions affecting the blood or bone marrow.
377
 
378
+ ---
379
 
380
+ ## โœ… Conclusion:
381
+ The model's prediction of patient readmission is most strongly influenced by the patient's history of previous hospital stays, indicating a potential for chronic or recurring health issues. The number of medications, time since the last stay, and the patient's age are also significant factors, highlighting the complexity of the patient's health condition and the potential for ongoing care needs.
382
 
383
+ While other factors such as CCI score, DRG severity, race, and blood cell health play a role, their impacts are less pronounced. Understanding these factors can help healthcare providers identify high-risk patients and implement targeted interventions to reduce the likelihood of readmission.
384
+
385
  """
386
 
387
  # ๐ŸŽญ **Show AI Response in a Stylish Chat Format**
388
  with st.chat_message("assistant"):
389
+ st.markdown(f"**๐Ÿ’ก AI Explanation:**\n\n")
390
+ st.markdown(dedent(ai_output))
391
  except Exception as e:
392
  st.error(f"โš ๏ธ Error retrieving response: {e}")
393
  st.stop()