開始使用免費開始

使用視覺化:lmplot

建立線性模型圖可以幫助你檢視變數是否與應變數相關。若有相關性,就很適合納入分析。若沒有,也不代表要丟棄,而是可能需要先做前處理或整理後再使用。

你的工作環境已提供 seaborn,慣用別名為 sns

本練習屬於課程

使用 PySpark 進行特徵工程

檢視課程

練習說明

  • 使用已載入的資料集 df,用 select() 篩選出 'SALESCLOSEPRICE' 與 'LIVINGAREA' 兩個欄位。
  • 使用 sample() 取樣 50% 的資料列,確保不重複抽樣,並將隨機種子設為 42。
  • 將 Spark DataFrame 轉為 pandas.DataFrame(),使用 toPandas()
  • 以 'SALESCLOSEPRICE' 為應變數、'LIVINGAREA' 為自變數,使用 seaborn 的 lmplot() 繪製線性模型圖。

動手互動練習

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

# Select a the relevant columns and sample
sample_df = df.____([____, ____]).____(____, ____, ____)

# Convert to pandas dataframe
pandas_df = sample_df.____()

# Linear model plot of pandas_df
sns.____(x=____, y=____, data=____)
plt.show()
編輯並執行程式碼