開始使用免費開始

無安打發生率的信賴區間

回到現代職棒時代的無安打間隔時間。請為最佳參數 \(\tau\) 產生 10,000 個 bootstrap 複本。繪製這些複本的直方圖,並回報 95% 信賴區間。

本練習屬於課程

Statistical Thinking in Python(第 2 部分)

檢視課程

練習說明

  • 使用你的 draw_bs_reps() 函式,從 nohitter_times 資料中為 \(\tau\) 產生 10000 個 bootstrap 複本。回想一下,最佳的 \(\tau\) 是資料的平均數
  • 使用 np.percentile() 計算 95% 信賴區間,並傳入兩個引數:陣列 bs_replicates,以及百分位數清單——在此為 2.597.5
  • 列印信賴區間。
  • 繪製 bootstrap 複本的直方圖。這部分已為你完成,按下送出即可看到圖表!

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Draw bootstrap replicates of the mean no-hitter time (equal to tau): bs_replicates
bs_replicates = ____

# Compute the 95% confidence interval: conf_int
conf_int = ____

# Print the confidence interval
print('95% confidence interval =', ____, 'games')

# Plot the histogram of the replicates
_ = plt.hist(bs_replicates, bins=50, density=True)
_ = plt.xlabel(r'$\tau$ (games)')
_ = plt.ylabel('PDF')

# Show the plot
plt.show()
編輯並執行程式碼