# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="view-in-github" colab_type="text"
# <a href="https://colab.research.google.com/github/syamkakarla98/DataScience_Head_Start/blob/master/Student_Preformance.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + [markdown] id="XOqRebkuslDm" colab_type="text"
# # Student Performance in Exams
#
# This notebook provides the in depth analysis on the [student performance in exams at public schools](http://roycekimmons.com/tools/generated_data/exams).
#
# ![img_exam](https://www.sciencenewsforstudents.org/wp-content/uploads/2019/11/860_test_anxiety.png)

# + [markdown] id="DQTcvgqHsrFG" colab_type="text"
# ## Importing Libraries

# + id="zbZfm-_1n-OJ" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 34} outputId="8e8f50d0-5dd1-4945-9776-8539926e21cb"
 # #!/usr/bin/env python -W ignore::DeprecationWarning

# Data Handling 
import pandas as pd
import numpy as np
from itertools import combinations

# Visualization
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px
from IPython.display import HTML
plt.rcParams['figure.figsize'] = (14, 8)
sns.set_style('whitegrid')

# Chand=ging directory
# %cd '/content/drive/My Drive/DataScience/Data_Science_Head_Start'

# + [markdown] id="sPeEpHcaswGU" colab_type="text"
# ## Reading Data

# + id="fam18NUGpCMV" colab_type="code" colab={}
df = pd.read_csv('data/StudentsPerformance.csv')

# + id="wX-yRwAoQS5S" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 34} outputId="954814bd-003e-4393-a107-d5a21f641a32"
df.shape

# + id="UXuJQnbxQHNj" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 235} outputId="ff945fc0-7151-4a23-e829-4e8df90ce609"
df.info()

# + id="aPbXmyyrQJtj" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 284} outputId="8351cd21-6dbf-40b9-a345-b8153d90772c"
df.describe()

# + [markdown] id="1UWVCuXts3tI" colab_type="text"
# ## Viewing data

# + id="pcUNCoOkp4VE" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 343} outputId="fb24a2b9-8cb7-41e0-9832-149406c69400"
df.reset_index()
df.head(10)

# + id="JEuqSJSpz8Zn" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 438} outputId="9c0a995c-e912-4e57-ea8f-865d6ec1b95c"
(df.head(20)
 .style
 .hide_index()
 .bar(color='#70A1D7', vmin=0, subset=['math score'])
 .bar(color='#FF6F61', vmin=0, subset=['reading score'])
 .bar(color='mediumspringgreen', vmin=0, subset=['writing score'])
 .set_caption(''))

# + [markdown] id="y2aqEHL3FYcq" colab_type="text"
# ### Analysis of categorical attributes
#
# ### A Bar Plot & Count Plot w.r.t **Gender**, **Race/ethnicity**, **Parental Level of Education**, **Lunch** and **Test Preparation Course**.

# + id="cpae18r40rHz" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 1000} outputId="c447f640-aa18-49b4-9c5e-14b71e02cd46"

for attribute in ['gender', 'race/ethnicity', 'parental level of education', 'lunch', 'test preparation course']:
  f, ax = plt.subplots(1,2)
  data = df[attribute].value_counts().sort_index()
  bar = sns.barplot(x = data.index, y = data, ax = ax[0], palette="Set2",)
  for item in bar.get_xticklabels():
    item.set_rotation(45)
  ax[1].pie(data.values.tolist() , labels= [i.title() for i in data.index.tolist()], autopct='%1.1f%%',shadow=True, startangle=90);
  plt.show()

# + [markdown] id="2eMpb4hULuRw" colab_type="text"
# ### Distribution Plots of Numeric Attributes **Math Score**, **Reading Score** and **wrtiting Score**

# + id="tGjg63hH-gmV" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 1000} outputId="2475b4ef-0630-4627-e6ee-2ff45dcb2141"

for lab, col in zip(['math score', 'reading score', 'writing score'], ['tomato', 'mediumspringgreen', 'blue']):
  sns.distplot(df[lab], label=lab.title(), color = col, ).set(xlabel=lab.title(), ylabel='Count')
  plt.show()


# + [markdown] id="e6DzmEabXEP-" colab_type="text"
# ### Relationship Between Numerical Attributes

# + id="PlbDwN4iDPtd" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 1000} outputId="b54dbdea-834e-42b4-f02e-b8cf622970b2"

for attr, col in zip(list(combinations(['math score', 'reading score', 'writing score'], 2)), ['#77DF79', '#82B3FF', '#F47C7C']):
  sns.jointplot(df[attr[0]], df[attr[1]], color = col)
  plt.show()

# + [markdown] id="fLtGL7xxf_oc" colab_type="text"
# ### Barplot between **Parent Level of education** and the student score in **Math**, **Reading** and **Writing**

# + id="nHkXnYabHnhn" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 580} outputId="b8c56798-d5ae-456d-b710-c723029989f6"

df.groupby('parental level of education')['math score', 'reading score', 'writing score'].mean().plot(kind = 'bar');


# + [markdown] id="oG1jE41wgVcU" colab_type="text"
# ### Barplot between **Parent Level of education** and the student score in **Reading** and **Writing**

# + id="0ehuDfQ0TWaC" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 729} outputId="905bfcd7-a157-45ee-975e-e14e8a7e5182"

cond_plot = sns.FacetGrid(data=df, col='parental level of education', hue='gender', col_wrap=3, height = 5)
cond_plot.map(sns.scatterplot, 'reading score', 'writing score' );

# + [markdown] id="j6tO75w8f9dQ" colab_type="text"
# ### Bar graph between **Race/Ethnicity** and **Test Preparation Course**

# + id="85dv0JwXa-a2" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 593} outputId="ccc426c0-208e-4bdf-bd71-0e11f09e9e3f"
df.groupby('race/ethnicity')['test preparation course'].value_counts().plot(kind = 'bar', colormap='Set2')
plt.ylabel('Count');

StarcoderdataJupyterScriptsDedupFiltered