統計量のばらつきを可視化する
これまでに、サンプル統計量のばらつきを計算してきました。ここでは、そのばらつきを可視化します。
あらかじめ読み込まれている population と、サンプルを抽出してサンプル統計量の配列を返す関数 get_sample_statistics() を使います。
ここでは、matplotlib のメソッド axis.hist() を内包した事前定義の関数 plot_hist() を使います。この関数は、渡された配列をビン分割してプロットします。これにより、サンプル統計量が単一の値ではなく、値の分布を持つことが確認できます。
この演習はコースの一部です
Pythonで学ぶ線形モデリング入門
演習の手順
populationをget_sample_statistics()に渡して、サンプル統計量の分布を取得します。- 各統計量の配列に対して、
np.linspace()を使ってヒストグラムのビン境界を定義します。 - 事前定義の
plot_hist()を 2 回使い、統計量の分布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')