資料符合我們的敘事嗎?
你已經用 Exponential 分配來建模無安打場次之間的時間。請先對真實資料建立 ECDF。再把理論 CDF 疊加到資料的 ECDF 上。這能幫助你檢查 Exponential 分配是否能描述觀察到的資料。
你可能需要回頭看看你在上一門課所寫的【計算 ECDF 的函式】以及【如何繪圖】的程式碼,作為提醒與參考。
https://campus.datacamp.com/courses/statistical-thinking-in-python-part-1/graphical-exploratory-data-analysis?ex=12 https://campus.datacamp.com/courses/statistical-thinking-in-python-part-1/graphical-exploratory-data-analysis?ex=13
本練習屬於課程
Statistical Thinking in Python(第 2 部分)
練習說明
- 以無安打之間的實際時間(
nohitter_times)計算 ECDF。使用你在前一門課寫的ecdf()函式。 - 用你在上一個練習取得的理論樣本(
inter_nohitter_time)建立一個 CDF。 - 使用
plt.plot()以折線繪出x_theor與y_theor,接著把真實資料的 ECDF(x與y)以散點疊加上去。為此,你需要在plt.plot()中,除了x與y外,另外指定關鍵字引數marker = '.'與linestyle = 'none'。 - 在圖上設定 2% 的邊界。
- 顯示圖形。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create an ECDF from real data: x, y
x, y = ____
# Create a CDF from theoretical samples: x_theor, y_theor
x_theor, y_theor = ____
# Overlay the plots
plt.plot(____, ____)
plt.plot(____, ____, marker=____, linestyle=____)
# Margins and axis labels
plt.margins(____)
plt.xlabel('Games between no-hitters')
plt.ylabel('CDF')
# Show the plot
plt.show()