解釋變異
你已經看到休士頓與拉斯維加斯之間的房租價格具有相關性。不過,一個城市的價格變動,在多大程度上能解釋另一個城市的價格變動?透過計算 R-squared,你可以精確量化這件事。
已為你載入拉斯維加斯(lasvegas_rents)與休士頓(houston_rents)的房租 NumPy 陣列,以及每次量測對應的 dates。套件 pandas(作為 pd)、NumPy(作為 np)、Matplotlib(作為 plt),以及 SciPy 的 stats 模組都已載入。
本練習屬於課程
Python 推論基礎
練習說明
- 計算
houston_rents與lasvegas_rents之間的 Pearson 相關係數。 - 印出該相關係數的平方。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Compute the correlation between Houston and Las Vegas
r, p_value = ____
# Print R-squared
____