เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

Introduce a margin in the dataset

Your final task for Chapter 1 is to create a margin in the dataset that you generated in the previous exercise and then display the margin in a plot. The ggplot2 library has been preloaded for you. Recall that the slope of the linear decision boundary you created in the previous exercise is 1.4.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Support Vector Machines in R

ดูคอร์ส

คำแนะนำการฝึกหัด

  • Introduce a margin delta of 0.07 units in your dataset.
  • Replot the dataset, displaying the margin boundaries as dashed lines and the decision boundary as a solid line.

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

#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
แก้ไขและรันโค้ด