データセットにマージンを導入する
第1章の最後のタスクは、前の演習で作成したデータセットにマージンを追加し、そのマージンをプロットで表示することです。ggplot2 ライブラリはすでに読み込まれています。前の演習で作成した線形の決定境界の傾きは 1.4 であることを思い出してください。
この演習はコースの一部です
Rで学ぶSupport Vector Machines
演習の手順
- データセットに 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