数据是否符合我们的假设?
本练习是课程的一部分
Python 统计思维(第 2 部分)
练习说明
- 使用前一门课程中您编写的
ecdf()函数,基于无安打之间的实际时间(nohitter_times)计算 ECDF。 - 基于您在上一个练习中获取的理论样本(
inter_nohitter_time)创建一个 CDF。 - 使用
plt.plot()将x_theor和y_theor以折线绘制。然后将真实数据的 ECDF(x和y)以点的形式叠加。为此,除了在plt.plot()中传入x和y,还需指定关键字参数marker = '.'和linestyle = 'none'。 - 将图形边距设为 2%。
- 显示图形。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Create an ECDF from real data: x, y
x, y = ____
# Create a CDF from theoretical samples: x_theor, y_theor
x_theor, y_theor = ____
# Overlay the plots
plt.plot(____, ____)
plt.plot(____, ____, marker=____, linestyle=____)
# Margins and axis labels
plt.margins(____)
plt.xlabel('Games between no-hitters')
plt.ylabel('CDF')
# Show the plot
plt.show()