視覺化統計量的變異
先前你已經計算過樣本統計量的變異。現在你要把這些變異視覺化。
我們已經預先載入了 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')