I am interested in test the SVM performance to classify several individuals into four groups/classes. When using the svmtrain LibSVM function from MATLAB, I am able to get the three equations used to classify those individuals among the 4 groups, based on the values of this equation. An scheme could be as follows:
All individuals (N)*
|
Group 1 (n1) <--- equation 1 ---> (N-n1)
|
(N-n1-n2) <--- equation 2 ---> Group 2 (n2)
|
Group 3 (n3) <--- equation 3 ---> Group 4(n4)
*N = n1+n2+n3+n4
Is there any way to get these equations using the svm function in the e1071 R package?
svmine1071uses the “one-against-one” strategy for multiclass classification (i.e. binary classification between all pairs, followed by voting). So to handle this hierarchical setup, you probably need to do a series of binary classifiers manually, like group 1 vs. all, then group 2 vs. whatever is left, etc.. Additionally, the basicsvmfunction does not tune the hyperparameters, so you will typically want to use a wrapper liketuneine1071, ortrainin the excellentcaretpackage.Anyway, to classify new individuals in R, you don’t have to plug numbers into an equation manually. Rather, you use the
predictgeneric function, which has methods for different models like SVM. For model objects like this, you can also usually use the generic functionsplotandsummary. Here is an example of the basic idea using a linear SVM:Tabulate actual class labels vs. model predictions:
Extract feature weights from
svmmodel object (for feature selection, etc.). Here,Sepal.Lengthis obviously more useful.To understand where the decision values come from, we can calculate them manually as the dot product of the feature weights and the preprocessed feature vectors, minus the intercept offset
rho. (Preprocessed means possibly centered/scaled and/or kernel transformed if using RBF SVM, etc.)This should equal what is calculated internally: