I have built a SVM model using the R package e1071 and the iris data set. I have split up the iris data into a training and test data and built the SVM from the training data. Now I would like to plot the test data into the same plot that show the training data and the SVM boundaries using the points
function. When I do this, however, quite a few of the test data points end up outside to the right of the plot, which shouldn't be possible considering the plot scale and the actual values of the test data. Here is the code I used:
# Import e1071 package and iris data set
library(e1071)
data("iris")
# Split the data into training and test data
index <- c(1:35, 51:85, 101:135)
iris_training <- iris[index, ]
iris_test <- iris[-index, ]
# Compute SVM model with linear kernel
svm_model <- svm(Species ~ Petal.Length + Petal.Width,
data=iris_training,
kernel='linear')
# Plot the data and decision boundaries
plot(svm_model,
data = iris_training[ , c(3, 4, 5)],
xlim = c(0.05, 2.55),
ylim = c(0.9, 7),
svSymbol = 1,
dataSymbol = 1,
symbolPalette = c("black", "blue", "red"))
# Plot the test data into the same plot
points(iris_test$Petal.Width,
iris_test$Petal.Length,
pch="x")
Any ideas how to fix this or how to work around this problem? Help greatly appreciated.