開始使用免費開始

90、95、99% 區間

你在阿拉斯加費爾班克斯的一家戶外探險公司擔任資料科學家。最近顧客受到 SO2 汙染影響,導致昂貴的行程取消。公司目前有 CO、NO2、O3 的感測器,但沒有 SO2 的感測器。

你已建立一個模型,能根據有感測器的汙染物數值來預測 SO2 的數值(載入為 pollution_model,一個 statsmodels 物件)。你想要調查哪一種汙染物的數值對模型的 SO2 預測影響最大。這能幫助你在規劃戶外行程時,知道該特別留意哪個汙染物的數值。為了在報告中呈現更多資訊,請對模型估計顯示多個不確定性等級。

本練習屬於課程

用 Python 改善你的資料視覺化

檢視課程

練習說明

  • 依照 alpha 清單中的數值,填入對應的區間寬度百分比(從 90、95、99%)。
  • 在 for 迴圈中,將區間著色為其指定的 color
  • 將迴圈的 width 百分比值傳給 plt.hlines(),以在圖例中加上標籤。

動手互動練習

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

# Add interval percent widths
alphas = [     0.01,  0.05,   0.1] 
widths = [ '__% CI', '__%', '__%']
colors = ['#fee08b','#fc8d59','#d53e4f']

for alpha, color, width in zip(alphas, colors, widths):
    # Grab confidence interval
    conf_ints = pollution_model.conf_int(alpha)
    
    # Pass current interval color and legend label to plot
    plt.hlines(y = conf_ints.index, xmin = conf_ints[0], xmax = conf_ints[1],
               colors = ____, ____ = width, linewidth = 10) 

# Draw point estimates
plt.plot(pollution_model.params, pollution_model.params.index, 'wo', label = 'Point Estimate')

plt.legend()
plt.show() 
編輯並執行程式碼