課程導論

Python 線性建模入門

Jason Vestuto

Data Scientist

第 1 章導言

章節導覽:

  • 動機範例
  • 資料視覺化
  • 敘述統計
Python 線性建模入門

旅程資料範例

點狀圖:距離對時間,英里對小時

Python 線性建模入門

作為描述的模型

# Range of y data, in miles
y_range = np.max(y) - np.min(y) = 300 - 0 = 300
# Range of x data, in hours
x_range = np.max(x) - np.min(x) = 6 - 0 = 6
# Estimating the speed
mph = y_range / x_range = 300 / 6 = 50
Python 線性建模入門

視覺化模型

資料與模型圖:距離對時間

Python 線性建模入門

模型預測

# Model as python expression
miles = 50*hours
# Model predicts distance is 300 miles at 6 hours
time = 6
distance = 50 * time = 50 * 6 = 300
def model(time):
    return 50*time

predicted_distance = model(time=10)
Python 線性建模入門

內插

距離對時間圖:在兩筆資料點間標示內插點

Python 線性建模入門

外插

距離對時間圖:在資料點之外較晚時間標示外插點

Python 線性建模入門

一起來練習吧!

Python 線性建模入門

Preparing Video For Download...