Hands-on SVM

1. Obtain an SVM model for forecasting the quality of variant with Class 2

library(e1071)
ds <- read.csv("wine.data")
ds_class2 <- ds[ds$Class==2,-1]
m <- svm(Proline ~ ., ds_class2)

2. Split the data set in two parts: one with 70% of the samples and the other with the remaining 30%. Obtain an SVM with the first part and apply it to the second. What was the resulting mean absolute error?

idx <- sample(1:nrow(ds_class2),nrow(ds_class2)*0.7)
tr <- ds_class2[idx,]
ts <- ds_class2[-idx,]

m <- svm(Proline ~ ., tr)
p <- predict(m, ts)

mae <- mean(abs(p - ts$Proline))
mae
## [1] 131.7057

3. Using the round() function, round the predictions obtained in the previous question to the nearest integer. Calculate the error rate of the resulting integers when compared to the true values.

p_new <- round(p)
mae_new <- mean(abs(p_new - ts$Proline))
mae_new
## [1] 131.6364