开始使用免费开始使用

可视化决策边界与间隔

在上一个练习中,您为一个线性可分的数据集构建了两个线性分类器:一个使用 cost = 1,另一个使用 cost = 100。本练习中,您将把这两个分类器的间隔可视化到同一幅图上。可用对象如下:

  • 训练数据集:trainset
  • cost = 1cost = 100 的分类器分别存于 svm_model_1svm_model_100
  • cost = 1 分类器的斜率与截距分别存于 slope_1intercept_1
  • cost = 100 分类器的斜率与截距分别存于 slope_100intercept_100
  • 两个 cost 对应的权重向量分别存于 w_1w_100
  • 训练数据的基础散点图存于 train_plot

已预先加载 ggplot2 库。

本练习是课程的一部分

R 中的支持向量机

查看课程

交互式实操练习

通过完成这段示例代码来试试这个练习。

#add decision boundary and margins for cost = 1 to training data scatter plot
train_plot_with_margins <- train_plot + 
    geom_abline(slope = ___, intercept = ___) +
    geom_abline(slope = ___, intercept = ___-1/w_1[2], linetype = "dashed")+
    geom_abline(slope = ___, intercept = ___+1/w_1[2], linetype = "dashed")

#display plot
train_plot_with_margins
编辑并运行代码