SVM

Use R package e1701, which has svm already implemented. As we use the function in e1701, we don't have unclassified observations as in the paper. They have accuracy rate of 93.3% for linear kernel and 94.4% for quadratic kernel. We have 31/34 = 91.2% correctly classified by linear kernel and 32/34 = 94.1% correctly classified by quadratic kernel.


In [1]:
library(e1071)
set.seed(201702)
load("../transformed data/paper3.rda")
load("DP.rda")

In [2]:
# build the data for R functions
r_train = data.frame(train_cl, Y = factor(golub_train_l))
r_test =data.frame( test_cl, Y = factor(golub_test_l))

# build svm with linear kernel
svm_linear = svm(Y~., data = r_train)
svm_l_trpr = predict(svm_linear, r_train)
svm_l_tepr = predict(svm_linear, newdata = r_test)

# Result summary
table(Train_Predicted  = svm_l_trpr, Train_Actual = golub_train_l)
table(Test_Predicted = svm_l_tepr, Test_Actual = golub_test_l)


               Train_Actual
Train_Predicted  0  1
              0 27  0
              1  0 11
              Test_Actual
Test_Predicted  0  1
             0 16  2
             1  4 12

In [3]:
#build svm with quadratic kernel
svm_quad = svm(Y~., data = r_train, kernel = "polynomial", degree = 2,  gamma =0.01, coef0 = 100)
svm_q_trpr = predict(svm_quad, r_train)
svm_q_tepr = predict(svm_quad, newdata = r_test)

# Result_summary
table(Train_Predicted  = svm_q_trpr, Train_Actual = golub_train_l)
table(Test_Predicted = svm_q_tepr, Test_Actual = golub_test_l)


               Train_Actual
Train_Predicted  0  1
              0 27  0
              1  0 11
              Test_Actual
Test_Predicted  0  1
             0 20  3
             1  0 11

In [ ]: