閱讀能力/生育率資料的 EDA
接下來幾個練習中,我們要探討全球女性識字率與生育率(定義為每位女性平均生育子女數)之間的相關性。為了便於分析與詮釋,我們將使用「不識字率」。
在正式分析之前,先做一些 EDA 會很有幫助。請繪製生育率相對於不識字率的散佈圖,並計算皮爾森相關係數。NumPy 陣列 illiteracy 包含多數國家的女性不識字率;陣列 fertility 則是對應的生育率。
此處你可能會需要回頭參考你在前一門課寫過的函式,用來計算皮爾森相關係數。
本練習屬於課程
Statistical Thinking in Python(第 2 部分)
練習說明
- 將
fertility(y 軸)對illiteracy(x 軸)繪製為散佈圖。 - 設定 2% 的邊界。
- 計算並印出
illiteracy與fertility的皮爾森相關係數。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Plot the illiteracy rate versus fertility
_ = plt.plot(____, ____, ____='.', ____='none')
# Set the margins and label axes
plt.margins(____)
_ = plt.xlabel('percent illiterate')
_ = plt.ylabel('fertility')
# Show the plot
plt.show()
# Show the Pearson correlation coefficient
print(pearson_r(____, ____))