在数据集中引入间隔
本章最后一项任务是:在上一练习中生成的数据集中创建一个间隔,并在图中显示该间隔。已为您预加载 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