開始使用免費開始

視覺化轉換後的徑向可分資料

在這個練習中,你要將本章先前建立的徑向可分資料集做座標轉換,並在 x1^2-x2^2 平面上視覺化。提醒一下,資料的分隔邊界是圓 x1^2 + x2^2 = 0.64(半徑 = 0.8 單位)。資料集已載入到資料框 df

本練習屬於課程

R 的支援向量機

檢視課程

練習說明

  • 將資料轉換到 x1^2-x2^2 平面。
  • 以轉換後的座標來視覺化資料。
  • 加上一條在轉換後座標中為線性的邊界。

動手互動練習

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

#transform data
df1 <- data.frame(x1sq = df$x1^2, x2sq = ___, y = df$y)

#plot data points in the transformed space
plot_transformed <- ggplot(data = df1, aes(x = ___, y = x___, color = y)) + 
    geom_point()+ guides(color = "none") + 
    scale_color_manual(values = c("red", "blue"))

#add decision boundary and visualize
plot_decision <- plot_transformed + geom_abline(slope = -1, intercept = ___)
plot_decision
編輯並執行程式碼