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

Visualizing support vectors using ggplot

In this exercise you will plot the training dataset you used to build a linear SVM and mark out the support vectors. The training dataset has been preloaded for you in the dataframe trainset and the SVM model is stored in the variable svm_model.

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

Support Vector Machines in R

ดูคอร์ส

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

  • Load ggplot2.
  • Plot the training dataset.
  • Mark out the support vectors on the plot using their indices from the SVM model.

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

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

#load ggplot
library(ggplot2)

#build scatter plot of training dataset
scatter_plot <- ggplot(data = ___, aes(x = x1, y = x2, color = y)) + 
    geom_point() + 
    scale_color_manual(values = c("red", "blue"))
 
#add plot layer marking out the support vectors 
layered_plot <- 
    scatter_plot + geom_point(data = trainset[svm_model$___, ], aes(x = x1, y = x2), color = "purple", size = 4, alpha = 0.5)

#display plot
layered_plot
แก้ไขและรันโค้ด