开始使用免费开始使用

可视化变换后的径向可分数据

在本练习中,您将把本章前面创建的径向可分数据集进行变换,并在 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
编辑并运行代码