開始使用免費開始

視覺化多個變數

當你開始考慮更多變數時,要同時把它們全部畫在一張圖上會越來越困難。除了用 x 與 y 軸呈現兩個數值變數外,你可以用顏色呈現第三個數值變數,並用分面呈現類別變數。不過,超過這個範圍之後,圖形通常就難以解讀了。雖然有一些專門的圖表類型(例如相關係數熱圖與平行座標圖)可以處理更多變數,但它們對每個變數提供的細節較少,而且不太適合用來視覺化模型預測。

在這裡,你會把散佈圖推到極限:在同一張圖中同時呈現房價、距離捷運站的距離、附近便利商店數量,以及屋齡。

taiwan_real_estate 已可使用。

本練習屬於課程

使用 Python 的 statsmodels 進行迴歸分析:中級

檢視課程

練習說明

  • taiwan_real_estate 中的每個 house_age_years 建立一個分面網格。
  • 使用 taiwan_real_estate 資料集,繪製以 sqrt_dist_to_mrt_m 為 x 軸、n_convenience 為 y 軸的散佈圖,並以 price_twd_msq 作為顏色。

動手互動練習

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

# Prepare the grid using taiwan_real_estate, for each house age category, colored by price_twd_msq
grid = ____(data=____,
            col=____,
            hue=____,
            palette="plasma")

# Plot the scatterplots with sqrt_dist_to_mrt_m on the x-axis and n_convenience on the y-axis
grid.map(____,
         ____,
         ____)

# Show the plot (brighter colors mean higher prices)
plt.show()
編輯並執行程式碼