視覺化遺漏值
把遺漏值畫出來,可以快速了解資料遺漏了多少。同時也能幫你看出變數是否呈現某種缺失的模式,這類情況需要小心處理,否則模型可能會產生偏誤。
哪個變數的遺漏值最多?先執行除了最後一行以外的所有程式碼找出答案。當你有把握後,填入該變數名稱,然後按下「Submit Answer」。
本練習屬於課程
使用 PySpark 進行特徵工程
練習說明
* 使用 select() 以清單 columns 篩選資料框 df,再用提供的 sample() 函式抽樣,並把結果指派給變數 sample_df。
* 將這個子集資料框轉為 pandas 的資料框 pandas_df,再用 pandas 的 isnull() 把這個 DataFrame 轉成 True/False。把結果存到 tf_df。
* 使用 seaborn 的 heatmap() 繪製 tf_df。
* 按下「Run Code」查看圖表。接著把遺漏值最多的變數名稱指定給 answer。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Sample the dataframe and convert to Pandas
____ = df.select(____).sample(False, 0.1, 42)
____ = ____.toPandas()
# Convert all values to T/F
tf_df = ____.____()
# Plot it
sns.____(data=____)
plt.xticks(rotation=30, fontsize=10)
plt.yticks(rotation=0, fontsize=10)
plt.show()
# Set the answer to the column with the most missing data
answer = '____'