To classify using SVM, follow these steps:
- Load the e1071 and caret packages:
> library(e1071) > library(caret)
- Read the data:
> bn <- read.csv("banknote-authentication.csv")
- Convert the outcome variable class to a factor:
> bn$class <- factor(bn$class)
- Partition the data:
> set.seed(1000) > t.idx <- createDataPartition(bn$class, p=0.7, list=FALSE)
- Build the model:
> mod <- svm(class ~ ., data = bn[t.idx,])
- Check model performance on training data by generating an error/classification confusion matrix:
> table(bn[t.idx,"class"], fitted(mod), dnn = c("Actual", "Predicted")) Predicted Actual 0 1 0 534 0 1 0 427
- Check model performance on the validation partition:
> pred <- predict(mod, bn[-t.idx,]) > table(bn[-t.idx, ...