常態分配的 PDF
在這個練習中,你會探索常態分配的 PDF,並學習如何用駭客式統計來繪製已知分配的 PDF。你將特別針對不同變異數的情況,繪製常態分配的 PDF。
本練習屬於課程
Statistical Thinking in Python (Part 1)
練習說明
- 從平均數為
20、標準差為1的常態分配抽取 100,000 個樣本。對標準差為3與10、平均數同為20的常態分配也做相同操作。將結果分別指定給samples_std1、samples_std3與samples_std10。 - 為每組樣本繪製長條圖;每張圖使用 100 個 bins,並加入關鍵字引數
density=True與histtype='step'。後者會讓圖形看起來更接近平滑的理論 PDF。你需要呼叫plt.hist()共 3 次。 - 按下送出以建立圖例,顯示你使用的標準差,並顯示你的圖表!不需要為座標軸加上標籤,因為我們尚未定義常態分配描述的是什麼;我們只是在觀察 PDF 的形狀。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Draw 100000 samples from Normal distribution with stds of interest: samples_std1, samples_std3, samples_std10
# Make histograms
# Make a legend, set limits and show plot
_ = plt.legend(('std = 1', 'std = 3', 'std = 10'))
plt.ylim(-0.01, 0.42)
plt.show()