Visualizing decision boundaries and margins
In the previous exercise you built two linear classifiers for a linearly separable dataset, one with cost = 1 and the other cost = 100. In this exercise you will visualize the margins for the two classifiers on a single plot. The following objects are available for use:
- The training dataset:
trainset. - The
cost = 1andcost = 100classifiers insvm_model_1andsvm_model_100, respectively. - The slope and intercept for the
cost = 1classifier is stored inslope_1andintercept_1. - The slope and intercept for the
cost = 100classifier is stored inslope_100andintercept_100. - Weight vectors for the two costs are stored in
w_1andw_100, respectively - A basic scatter plot of the training data is stored in
train_plot
The ggplot2 library has been preloaded.
This exercise is part of the course
Support Vector Machines in R
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
#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