Reputation: 574
How is total accuracy actually calculated in e1071::svm()? It is not the same as calculated from the confusion table:
> x <- subset(iris, select = -Species)
> y <- iris$Species
> model <- svm(x, y,cross=10)
> model$tot.accuracy
[1] 96
> caret::confusionMatrix(y,model$fitted)
Confusion Matrix and Statistics
Reference
Prediction setosa versicolor virginica
setosa 50 0 0
versicolor 0 48 2
virginica 0 2 48
Overall Statistics
Accuracy : 0.9733
...
Upvotes: 0
Views: 723
Reputation: 8602
The total accuracy is the cross-validation accuracy obtained during the fitting procedure. For each split of the data, the model is fit and accuracy on the respective validation dataset is calculated.
The individual accuracy can be obtained from
cv_accuracies <- model$accuracies
all.equal(mean(cv_accuracies), model$tot.accuracy)
[1] TRUE
Note that as the cross-validation splits the data into 10 different training and validation pairs, where the validation set is not used in the fitting procedure, this accuracy will be different compared to the accuracy of when predicting the final model to the entire training set.
sum(fitted(model) == y)/length(y)
[1] 0.97333333
mean(cv_accuracies)
[1] 96.66667
(note one is multiplied by 100 as standard)
Upvotes: 0