開始使用免費開始

建模的理由:外插法(Extrapolation)

建模的另一個常見用途是進行外插(extrapolation),也就是在量測資料的範圍(time 的最小到最大值)之外,估計「外部」「更遠」的資料值。在本練習中,我們量測了 0 到 5 小時的距離,但我們想估計若行駛 8 小時會走多遠。延續前一個練習使用的同一筆資料集,我們已經建立了線性模型 distance = model(time)。請使用 model() 來對遠大於量測時間範圍的時間點進行距離預測。

context figure

本練習屬於課程

Python 線性建模入門

檢視課程

練習說明

  • 使用 distance = model(time),對超出量測資料範圍的 time=8 小時進行外插。
  • 列印預測的 distance,然後檢查它是否小於或等於 400
  • 如果你的車在加滿油的情況下,最多能行駛 400 英里,而開車回家需要 8 小時,你是否能不加油就抵達?若能抵達,請將 answer=True;若會沒油,請將 answer=False

動手互動練習

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

# Select a time not measured.
time = 8

# Use the model to compute a predicted distance for that time.
distance = model(____)

# Inspect the value of the predicted distance traveled.
print(distance)

# Determine if you will make it without refueling.
answer = (____ <= 400)
print(answer)
編輯並執行程式碼