最小平方法的線性回歸

Statistical Thinking in Python(第 2 部分)

Justin Bois

Lecturer at the California Institute of Technology

2008 年美國搖擺州選舉結果

ch1-2.002.png

1 資料取自 Data.gov (https://www.data.gov/)
Statistical Thinking in Python(第 2 部分)

2008 年美國搖擺州選舉結果

ch1-2.004.png

1 資料取自 Data.gov (https://www.data.gov/)
Statistical Thinking in Python(第 2 部分)

2008 年美國搖擺州選舉結果

ch1-2.007.png

1 資料取自 Data.gov (https://www.data.gov/)
Statistical Thinking in Python(第 2 部分)

2008 年美國搖擺州選舉結果

ch1-2.008.png

1 資料取自 Data.gov (https://www.data.gov/)
Statistical Thinking in Python(第 2 部分)

殘差

ch1-2.010.png

1 資料取自 Data.gov (https://www.data.gov/)
Statistical Thinking in Python(第 2 部分)

最小平方法

  • 尋找使殘差平方和最小的參數的過程。
Statistical Thinking in Python(第 2 部分)

使用 np.polyfit() 的最小平方法

slope, intercept = np.polyfit(total_votes,
                              dem_share, 1)

slope
4.0370717009465555e-05
intercept
40.113911968641744
Statistical Thinking in Python(第 2 部分)

一起來練習吧!

Statistical Thinking in Python(第 2 部分)

Preparing Video For Download...