對所有 Anscombe 資料做線性迴歸
現在,為了驗證 Anscombe 的 4 組資料在以線性迴歸求得的斜率與截距上皆相同,你將為每一組資料計算斜率與截距。資料以清單儲存;anscombe_x = [x1, x2, x3, x4] 與 anscombe_y = [y1, y2, y3, y4]。例如,x2 與 y2 是第 2 組 Anscombe 資料的 x 與 y 數值。
本練習屬於課程
Statistical Thinking in Python(第 2 部分)
練習說明
- 撰寫一個
for迴圈,對每一組 Anscombe 資料執行下列動作:- 計算斜率與截距。
- 印出斜率與截距。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Iterate through x,y pairs
for x, y in zip(____, ____):
# Compute the slope and intercept: a, b
a, b = ____
# Print the result
print('slope:', a, 'intercept:', b)