可视化统计量的变异性
此前,您已经计算过样本统计量的变异性。现在,您将把这种变异性可视化。
我们已预加载了 population,并提供了预定义函数 get_sample_statistics() 用于抽取样本并返回样本统计量数组。
这里将使用预定义的 plot_hist() 函数,它封装了 matplotlib 的 axis.hist() 方法,既负责分箱也负责绘图。这样,您可以看到样本统计量并非只有单个值,而是形成一个取值分布。
本练习是课程的一部分
Python 线性建模入门
练习说明
- 将
population传入get_sample_statistics(),得到样本统计量的分布。 - 使用
np.linspace()为每个统计量数组定义直方图的箱体边界。 - 预定义的
plot_hist()调用两次,分别绘制统计量分布means和deviations的两个直方图。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Generate sample distribution and associated statistics
means, stdevs = get_sample_statistics(____, num_samples=100, num_pts=1000)
# Define the binning for the histograms
mean_bins = np.____(97.5, 102.5, 51)
std_bins = np.____(7.5, 12.5, 51)
# Plot the distribution of means, and the distribution of stdevs
fig = plot_hist(data=____, bins=____, data_name="Means", color='green')
fig = plot_hist(data=____, bins=____, data_name="Stdevs", color='red')