Visualizing an SVM fit
To visualize the built model, one can first use the plot function to generate a scatter plot of data input and the SVM fit. In this plot, support vectors and classes are highlighted through the color symbol. In addition to this, one can draw a contour filled plot of the class regions to easily identify misclassified samples from the plot.
Getting ready
In this recipe, we will use two datasets: the iris
dataset and the telecom churn
dataset. For the telecom churn
dataset, one needs to have completed the previous recipe by training a support vector machine with SVM and to have saved the SVM fit model.
How to do it...
Perform the following steps to visualize the SVM fit object:
- Use SVM to train the support vector machine based on the
iris
dataset and use theplot
function to visualize the fitted model:
> data(iris) > model.iris = svm(Species~., iris) > plot(model.iris, iris, Petal.Width ~ Petal.Length, slice = list(Sepal.Width ...