开始使用免费开始使用

分类变量的效应量

在奥斯汀市员工数据中,您已经看到不同职位的性别分布并不均衡。那么,族裔是否也是如此?族裔与所任职位之间的关联有多强?在本练习中,您将深入分析并回答这个问题。

已为您加载了一个用于比较职位与族裔的 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)
编辑并运行代码