開始使用免費開始

繪製成長曲線

你在前一題看到成長曲線的信賴區間非常窄。這裡你將以視覺方式探索:把多條自助法(bootstrap)線與成長曲線一起畫出來。你會使用 plt.semilogy() 將 y 軸設為對數刻度。這代表你需要把理論的線性迴歸曲線取指數,才能拿來繪圖。

本練習屬於課程

統計思維個案研究

檢視課程

練習說明

  • 使用 plt.semilogy() 繪出資料點。numpy 陣列 tbac_area 已在你的命名空間中。
  • 使用 np.array() 產生用來繪製自助法線條的時間值,命名為 t_bs。時間應從 0 到 14 小時。
  • 撰寫一個 for 迴圈,繪出前 100 組自助法重抽的對應迴歸線。你在上一題計算的 numpy 陣列 growth_rate_bs_repslog_a0_bs_reps 已在命名空間中。
    • 使用 np.exp() 對線性迴歸線取指數,計算成長曲線。
    • 使用 plt.semilogy() 繪製理論直線,並加入參數 linewidth=0.5alpha=0.05color='red'
  • 加上座標軸標籤並顯示圖形。x 與 y 軸的合適標籤分別為 'time (hr)''area (sq. µm)'

動手互動練習

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

# Plot data points in a semilog-y plot with axis labeles
_ = ____(____, ____, marker='.', linestyle='none')

# Generate x-values for the bootstrap lines: t_bs
t_bs = ____([____, ____])

# Plot the first 100 bootstrap lines
for i in range(____):
    y = ____(____[i] * ____ + ____[i])
    _ = ____(____, ____, linewidth=____, alpha=____, color=____)
    
# Label axes and show plot
_ = plt.xlabel('____')
_ = plt.ylabel('____')
____
編輯並執行程式碼