MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Support Vector Machines in R

Lihat Kursus

Petunjuk latihan

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

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

#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
Edit dan Jalankan Kode