類別變數的效果量
你在奧斯汀市政府員工的資料裡看到,不同職稱的性別分佈並不平均。那族裔是否也一樣呢?族裔和所任職稱之間的關聯程度又有多大?在這個練習中,你將深入分析並回答這個問題。
已為你載入一個比較職稱與族裔的 DataFrame(employees_df),以及 pandas(作為 pd)、NumPy(作為 np),還有 SciPy 的 stats。
本練習屬於課程
Python 推論基礎
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Compute the chi-squared statistic
chi2, p, d, expected = stats.____(____)
# Compute the DOF using the number of rows and columns
dof = min(____.shape[0] - 1, ____.shape[1] - 1)
# Compute the total number of people
n = np.sum(____.values)
# Compute Cramer's V
v = np.____((____ / ____) / ____)
print("Cramer's V:", v, "\nDegrees of freedom:", dof)