在資料集中加入邊界
第 1 章的最後一個任務,是在你於上一個練習產生的資料集中建立一個邊界,並在圖上將其顯示出來。ggplot2 函式庫已為你預先載入。回想一下,你在上一個練習建立的線性決策邊界,其斜率為 1.4。
本練習屬於課程
R 的支援向量機
練習說明
- 在你的資料集中加入大小為 0.07 單位的邊界
delta。 - 重新繪製資料集,並以虛線顯示邊界線、以實線顯示決策邊界。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
#set margin
delta <- ___
# retain only those points that lie outside the margin
df1 <- df[abs(1.4*df$x1 - df$x2) > delta, ]
#build plot
plot_margins <- ggplot(data = df1, aes(x = x1, y = x2, color = y)) + geom_point() +
scale_color_manual(values = c("red", "blue")) +
geom_abline(slope = ___, intercept = 0)+
geom_abline(slope = ___, intercept = ___, linetype = "dashed") +
geom_abline(slope = ___, intercept = ___, linetype = "dashed")
#display plot
plot_margins