Skip to content
Analysis of reading exam scores
0
  • AI Chat
  • Code
  • Report
  • Analyzing exam scores

    Now let's now move on to the competition and challenge.

    📖 Background

    Your best friend is an administrator at a large school. The school makes every student take year-end math, reading, and writing exams.

    Since you have recently learned data manipulation and visualization, you suggest helping your friend analyze the score results. The school's principal wants to know if test preparation courses are helpful. She also wants to explore the effect of parental education level on test scores.

    💾 The data

    The file has the following fields (source):
    • "gender" - male / female
    • "race/ethnicity" - one of 5 combinations of race/ethnicity
    • "parent_education_level" - highest education level of either parent
    • "lunch" - whether the student receives free/reduced or standard lunch
    • "test_prep_course" - whether the student took the test preparation course
    • "math" - exam score in math
    • "reading" - exam score in reading
    • "writing" - exam score in writing

    💪 Challenge

    Create a report to answer the principal's questions. Include:

    1. What are the average reading scores for students with/without the test preparation course?
    2. What are the average scores for the different parental education levels?
    3. Create plots to visualize findings for questions 1 and 2.
    4. [Optional] Look at the effects within subgroups. Compare the average scores for students with/without the test preparation course for different parental education levels (e.g., faceted plots).
    5. [Optional 2] The principal wants to know if kids who perform well on one subject also score well on the others. Look at the correlations between scores.
    6. Summarize your findings.

    Firstly, we import needed packages and read the data.

    # Importing the pandas and matplotlib.pyplot 
    import pandas as pd
    import matplotlib.pyplot as plt
    import numpy as np
    
    # Reading in the data
    df = pd.read_csv('data/exams.csv')
    

    Let's now calculate the average reading scores for students with and without the test preparation course.

    mean_prep = df.groupby("test_prep_course").agg({"reading":"mean"})
    print(mean_prep)

    As

    Our results can be visualized as follows.

    
    
    prep_true = df[df["test_prep_course"]=="completed"]
    prep_false = df[df["test_prep_course"]=="none"]
    
    
    fig, ax = plt.subplots()
    ax.hist(prep_true["reading"],histtype ="step", label="completed",bins =[0,10,20,30,40,50,60,70,80,90,100], color="green")
    ax.hist(prep_false["reading"],histtype ="step",label ="none",bins =[0,10,20,30,40,50,60,70,80,90,100],color="red")
    ax.legend(loc ="upper left")
    ax.axvline(prep_true["reading"].mean(), color='green', linestyle='dashed', linewidth=1)
    ax.axvline(prep_false["reading"].mean(), color='red', linestyle='dashed', linewidth=1)
    ax.set_ylabel("# of Students")
    ax.set_xlabel("Exam score (0-100)")
    ax.set_title("Distribution of reading scores for students with/without the test preparation course")
    plt.show()

    Parents

    print(df["parent_education_level"].unique())
    
    df["parent_education_level"] = df["parent_education_level"].replace(["high school"],"some high school")
    print(df["parent_education_level"].unique())
    
    mean_parent = df.groupby("parent_education_level").agg(Mean=('reading', np.mean),Std=('reading', np.std)).sort_values("Mean", ascending = False)
    print(mean_parent)
    fig, ax =plt.subplots()
    ax.bar(mean_parent.index, mean_parent["Mean"],yerr=mean_parent["Std"])
    ax.set_xticklabels( mean_parent.index, rotation = 90)
    
    ax.set_ylabel("Reading score")
    ax.set_title('Average reading scores by parent education level')
    
    plt.show()
    
    
    mean_parent_prep = df.groupby(["parent_education_level","test_prep_course"]).agg(Mean=('reading', np.mean),Std=('reading', np.std)).sort_values("parent_education_level", ascending = False)
    
    mean_parent_prep = mean_parent_prep.reset_index(drop=False)
    print(mean_parent_prep.sort_values("Mean",ascending =False))
    
    mean_parent_prep_true = mean_parent_prep[mean_parent_prep["test_prep_course"]=="completed"]
    mean_parent_prep_false = mean_parent_prep[mean_parent_prep["test_prep_course"]=="none"]
    
    ind = np.arange(mean_parent_prep_true.shape[0])
    width = 0.35       
    
    fig, ax = plt.subplots()
    ax.bar(mean_parent_prep_true["parent_education_level"], mean_parent_prep_true["Mean"], width, color='green', yerr=mean_parent_prep_true["Std"], label ="completed")
    ax.bar(ind + width, mean_parent_prep_false["Mean"], width, color='red', yerr=mean_parent_prep_false["Std"], label ="none")
    ax.set_xticklabels( mean_parent_prep_true["parent_education_level"], rotation = 90)
    ax.legend(loc="lower left")
    plt.show()
    
    scores = df[["reading","math","writing"]]
    
    corrMatrix = scores.corr()
    print(corrMatrix)
    
    ‌
    ‌
    ‌