In [ ]:
#numeric variable data visualization
In [ ]:
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
In [ ]:
df=pd.read_csv('student.csv')
df.head()
Out[ ]:
gender ethnicity parental_education lunch test_preparation_course math_score reading_score writing_score
0 female group B bachelor's degree standard none 72 72 74
1 female group C some college standard completed 69 90 88
2 female group B master's degree standard none 90 95 93
3 male group A associate's degree free/reduced none 47 57 44
4 male group C some college standard none 76 78 75
In [ ]:
#histplot
plt.figure(figsize=(10,5))
sns.histplot(data= df, x='math_score', color='lightgreen', kde=True,
             fill=False, binwidth= 5)
plt.title('Math Score Distribution')
plt.xlabel('Math Score')
plt.show()
No description has been provided for this image
In [ ]:
#kdeplot: a smoother version of histogram
plt.figure(figsize=(10,5))
sns.kdeplot(data= df, x='math_score', color='green', fill=True,
            alpha= 0.1, linewidth=2, linestyle= '--')#alpha is the transperancy from a range of 0 to 1
plt.title('Math Score Distribution')
plt.xlabel('Math Score')
plt.show()
No description has been provided for this image
In [ ]:
# math_score distribution across gender
plt.figure(figsize=(4,3))
sns.histplot(data= df, x='math_score', hue='gender', kde=True,
             fill=False, binwidth= 5,
             palette={'female':'lightpink', 'male':'lightblue'})
plt.title('Math Score Distribution')
plt.xlabel('Math Score')
plt.show()
No description has been provided for this image
In [ ]:
plt.figure(figsize=(4,3))
sns.kdeplot(data= df, x='math_score', hue='gender', fill=True,
             alpha= 0.2, linewidth=2, linestyle= '-', common_norm=False,
             palette={'female':'lightpink', 'male':'lightblue'})
plt.title('Math Score Distribution')
plt.xlabel('Math Score')
plt.show()
#common_norm=False separates the data into independant datasets,
#True combines them
No description has been provided for this image
In [ ]:
#explore the math distribution across test_preparation_course
In [ ]:
plt.figure(figsize=(5,3))
sns.histplot(data= df, x='math_score', hue='test_preparation_course', kde=True,
             fill=True, binwidth= 5,
             palette={'none':'grey', 'completed':'purple'},
             element='step')
plt.show()
No description has been provided for this image
In [ ]:
plt.figure(figsize=(5,3))
sns.kdeplot(data= df, x='math_score', hue='test_preparation_course', fill=True,
             alpha= 0.1, linewidth=1, linestyle= '-', common_norm=False,
             palette={'none':'grey', 'completed':'purple'})
plt.show()
No description has been provided for this image
In [ ]:
# how math score spread across ethnicity
In [ ]:
plt.figure(figsize=(5,3))
sns.kdeplot(data=df, x='math_score', hue='ethnicity', fill=True,
            alpha=0.2, linewidth=1, linestyle='-', common_norm=False)
plt.show()
No description has been provided for this image
In [ ]:
#Summary- numeric data visualization
#1. histogram (histplot)
#2. kdeplot
#3. boxplot
In [ ]:
#boxplot- distribution of math score
In [ ]:
plt.figure(figsize=(5,3))
sns.boxplot(data=df, x='math_score', color='lightgreen')
plt.show()
No description has been provided for this image
In [ ]:
#math score distribution across lunch
In [ ]:
sns.catplot(data=df, y='math_score', x='lunch', kind= 'box', hue= 'lunch')
plt.show()
No description has been provided for this image
In [ ]:
sns.catplot(data=df, y='math_score', x='parental_education', kind= 'box', hue= 'parental_education')
plt.xticks(rotation=20)
plt.show()
No description has been provided for this image
In [ ]:
# scatterplot - two different numeric variables
In [ ]:
plt.figure(figsize=(6,5))
sns.scatterplot(data=df, y='math_score', x='reading_score', hue='gender',
                palette={'female':'lightpink', 'male':'lightblue'}, marker='x', s=50)
plt.show()
No description has been provided for this image
In [ ]: