Skip to content
Competition - hospital readmissions
  • AI Chat
  • Code
  • Report
  • Reducing hospital readmissions

    📖 Background

    You work for a consulting company helping a hospital group better understand patient readmissions. The hospital gave you access to ten years of information on patients readmitted to the hospital after being discharged. The doctors want you to assess if initial diagnoses, number of procedures, or other variables could help them better understand the probability of readmission.

    They want to focus follow-up calls and attention on those patients with a higher probability of readmission.

    💾 The data

    You have access to ten years of patient information (source):

    Information in the file
    • "age" - age bracket of the patient
    • "time_in_hospital" - days (from 1 to 14)
    • "n_procedures" - number of procedures performed during the hospital stay
    • "n_lab_procedures" - number of laboratory procedures performed during the hospital stay
    • "n_medications" - number of medications administered during the hospital stay
    • "n_outpatient" - number of outpatient visits in the year before a hospital stay
    • "n_inpatient" - number of inpatient visits in the year before the hospital stay
    • "n_emergency" - number of visits to the emergency room in the year before the hospital stay
    • "medical_specialty" - the specialty of the admitting physician
    • "diag_1" - primary diagnosis (Circulatory, Respiratory, Digestive, etc.)
    • "diag_2" - secondary diagnosis
    • "diag_3" - additional secondary diagnosis
    • "glucose_test" - whether the glucose serum came out as high (> 200), normal, or not performed
    • "A1Ctest" - whether the A1C level of the patient came out as high (> 7%), normal, or not performed
    • "change" - whether there was a change in the diabetes medication ('yes' or 'no')
    • "diabetes_med" - whether a diabetes medication was prescribed ('yes' or 'no')
    • "readmitted" - if the patient was readmitted at the hospital ('yes' or 'no')

    Acknowledgments: Beata Strack, Jonathan P. DeShazo, Chris Gennings, Juan L. Olmo, Sebastian Ventura, Krzysztof J. Cios, and John N. Clore, "Impact of HbA1c Measurement on Hospital Readmission Rates: Analysis of 70,000 Clinical Database Patient Records," BioMed Research International, vol. 2014, Article ID 781670, 11 pages, 2014.

    import pandas as pd
    df = pd.read_csv('data/hospital_readmissions.csv')
    df.head()

    💪 Competition challenge

    Create a report that covers the following:

    1. What is the most common primary diagnosis by age group?
    2. Some doctors believe diabetes might play a central role in readmission. Explore the effect of a diabetes diagnosis on readmission rates.
    3. On what groups of patients should the hospital focus their follow-up efforts to better monitor patients with a high probability of readmission?

    🧑‍⚖️ Judging criteria

    CATEGORYWEIGHTINGDETAILS
    Recommendations35%
    • Clarity of recommendations - how clear and well presented the recommendation is.
    • Quality of recommendations - are appropriate analytical techniques used & are the conclusions valid?
    • Number of relevant insights found for the target audience.
    Storytelling35%
    • How well the data and insights are connected to the recommendation.
    • How the narrative and whole report connects together.
    • Balancing making the report in-depth enough but also concise.
    Visualizations20%
    • Appropriateness of visualization used.
    • Clarity of insight from visualization.
    Votes10%
    • Up voting - most upvoted entries get the most points.

    ⌛️ Time is ticking. Good luck!

    # Import important/useful libraries
    import numpy as np
    import pandas as pd
    import matplotlib.pyplot as plt
    import seaborn as sns
    
    # Apply default settings to Seaborn
    sns.set_style('whitegrid')
    sns.set_context('notebook')
    
    # Load the CSV to a data frame
    hospitalDF = pd.read_csv('data/hospital_readmissions.csv')
    # Determine the Most Common Primary Diagnosis per Age Category
    
    # Get a count of all the primary diagnoses by age category
    primaryCountsByAge = hospitalDF.groupby(['age', 'diag_1']).size().to_frame('Count')
    
    # Use the counts to calculate percentages
    # This will be a useful way to 'normalize' the data so it is easier to visualize
    primaryCountsByAge['Percentage'] = 100.0 * primaryCountsByAge['Count'].div( primaryCountsByAge.groupby(['age'])['Count'].sum() )
    primaryCountsByAge = primaryCountsByAge.reset_index()
    
    # Graph the percentage results
    g = sns.catplot( kind='bar', data=primaryCountsByAge, x='diag_1', y='Percentage', col='age')
    g.fig.suptitle('Primary Diagnoses By Age Category', y=1.1)
    g.set( xlabel='Primary Diagnosis', 
           ylabel='Percentage of Total Cases')
    g.tick_params(axis='x', rotation=90)
    g.set_titles("Age Category: {col_name}")
    
    plt.show()
    def getReadmissionStats ( title:str, subset ):
        readmittedCount = (hospitalDF[subset]['readmitted'] == 'yes').sum()
        notReadmittedCount = (hospitalDF[subset]['readmitted'] == 'no').sum()
        return (title, notReadmittedCount, readmittedCount, 100.0 * (readmittedCount /(readmittedCount + notReadmittedCount)) )
        
    # Determine which patients had a Diabetes diagnosis
    diabetic1 = hospitalDF['diag_1'] == 'Diabetes'
    diabetic2 = hospitalDF['diag_2'] == 'Diabetes'
    diabetic3 = hospitalDF['diag_3'] == 'Diabetes'
    
    cases = [
        getReadmissionStats( 'None', np.invert(diabetic1 | diabetic2 | diabetic3) ),
        getReadmissionStats( 'Any', diabetic1 | diabetic2 | diabetic3 ),
        getReadmissionStats( 'All', diabetic1 & diabetic2 & diabetic3 ),
        getReadmissionStats( 'First', diabetic1 ),
        getReadmissionStats( 'Second', diabetic2 ),
        getReadmissionStats( 'Third', diabetic3 ),
        getReadmissionStats( 'First or Second', diabetic1 | diabetic2 ),
        getReadmissionStats( 'First or Third', diabetic1 | diabetic3 ),
        getReadmissionStats( 'Second or Third', diabetic2 | diabetic3 ),
        getReadmissionStats( 'First and Second', diabetic1 & diabetic2 ),
        getReadmissionStats( 'First and Third', diabetic1 & diabetic3 ),
        getReadmissionStats( 'Second and Third', diabetic2 & diabetic3 ),
    ]
    
    titles, noCounts, yesCounts, yesPercent = zip( *cases )
    
    diabeticReadmissionDF = pd.DataFrame({
        'Diabetic Diagnosis': titles, 
        'Not Readmitted': noCounts, 
        'Readmitted': yesCounts, 
        'Percent Readmitted': yesPercent 
    })
    
    print( diabeticReadmissionDF )