In [ ]:
#question 1
#please define and visualize the following function using python
# y= x^2 + 2*x + 6
#hint linspace()
# input variable [0,20]: 50 data points across
#purple line

import numpy as np
import matplotlib.pyplot as plt

$$ y= x^2+2*x+6 $$

In [ ]:
x=np.linspace(0,20,50)
y=x**2+2*x+6
plt.figure(figsize=(5,3))
plt.plot(x,y, color= 'purple', linewidth=3)
plt.show()
No description has been provided for this image
In [ ]:
#question 2
#load and read student data
#explore the distribution of test_preparation_course
#set different colors to dfferent groups
In [ ]:
import pandas as pd
import seaborn as sns
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 [ ]:
plt.figure(figsize=(5,3))
sns.countplot(data= df, x= 'test_preparation_course', hue= 'test_preparation_course',
              palette={'none':'steelblue','completed':'red'})
plt.show()
No description has been provided for this image
In [ ]:
#question 3
#use visualization to explore which group
 #(text_preparation_course: none/completed) has better reading_score
In [ ]:
sns.catplot(data= df, x='test_preparation_course', y='reading_score', kind= 'box', hue= 'test_preparation_course',
            palette={'none':'steelblue', 'completed': 'red'}) #could of used kind='violin' too
plt.show()
No description has been provided for this image
In [ ]: