開始使用免費開始

用 t-SNE 區分房價

t-SNE 是一種非線性降維技術。它會將高維資料嵌入到較低維度的空間中。在這個過程中,它會盡量讓點保持在原本鄰居的附近。你將建立一張 t-SNE 圖,並拿來與上一個練習中的 PCA 圖比較。PCA 會保留資料的整體(全域)結構,但不一定能保留局部結構。t-SNE 則會透過在低維空間中維持高維空間的鄰近關係,來保留局部結構。你會在圖中看到這個差異。

你將對 house_sales_df 套用 t-SNE 做降維。house_sales_df 的目標變數是 price。已為你載入 tidyverseRtsne 套件。

本練習屬於課程

R 的降維

檢視課程

練習說明

  • 使用 Rtsne()house_sales_df 擬合 t-SNE。
  • 將 t-SNE 的 X 與 Y 座標繫結回 house_sales_df
  • 使用 ggplot() 繪製 t-SNE 結果,並以顏色編碼目標變數。

動手互動練習

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

# Fit t-SNE
set.seed(1234)
tsne <- ___(___ %>% select(-___), check_duplicates = FALSE)

# Bind t-SNE coordinates to the data frame
tsne_df <- ___ %>% 
  ___(tsne_x = ___$___[,___], tsne_y = ___$___[,___])

# Plot t-SNE
___ %>% 
  ___(aes(x = ___, y = ___, color = ___)) +
  geom_point() +
  scale_color_gradient(low="gray", high="blue")
編輯並執行程式碼