Helpful Hints for using SVMs in R
Overview
As noted, you may use any implementation of the SVM algorithm that you choose, and I would recommend reading over this tutorial, which will walk you through the process of how to use the LIBSVM library.
Hints
A few additionally notes that may be helpful.
To install the LIBSVM package you need to run:
install.packages('e1071', dependencies = TRUE)
Then, to load it, you run:
library (e1071)
The RBF kernel to experiment with is called "radial"
If the column you are trying to predict is numeric, the SVM algorithm will default to regression. You can force it to use classification with a type="C" parameter.
In order to use the
testset[,-2]
notation, you need to know which index your class value is, and remember that it is 1-based. Please note that in Python "-2" means, two from the end. In R, "-2" means, everything except 2.The tutorial above shows you how to create a confusion matrix with a command such as:
confusion_matrix <- table(pred = prediction, true = testset[,2])
You can also compute the accuracy using something like the following (assuming the dataset is "vowel_test" and the column of interest is called "Class":
agreement <- prediction == vowel_test$Class
accuracy <- prop.table(table(agreement))
At the risk of making this assignment too easy, and not helping you learn R as well as you should. You might also consider: even more helpful hints for using SVMs in R.