I am implementing machine learning algorithm for multiclass classification problem in R programming. The problem is that when I predict the accuracy I am getting around 90% accuracy but when I calculate the AUC score I am getting more than 1. Will the AUC support multi-class classification?
Which is the better approach to consider the evaluation metric of machine learning model for multi class classification?
Below is my code
library(dplyr)
smp_size <- floor(0.80 * nrow(New_data))
set.seed(123)
train_ind <- sample(seq_len(nrow(New_data)), size = smp_size)
train <- New_data[train_ind, ]
test <- New_data[-train_ind, ]
train_features <- train[,-ncol(train)]
train_labels <- train[,ncol(train)]
test_features <- test[,-ncol(test)]
test_labels <- test[,ncol(test)]
library(e1071)
library(rpart)
library(mlbench)
svm.model <- svm(as.factor(train$labels) ~ ., data = train,cross = 10)
class(svm.model)
summary(svm.model)
print(svm.model)
svm_pred <- predict(svm.model,test_features)
length(svm_pred)
length(test_labels)
table(pred = svm_pred, true = t(test_labels))
conf_matrix <- table(svm_pred, test_labels)
conf_matrix
library(MLmetrics)
Accuracy(svm_pred, test_labels)
AUC(svm_pred, test_labels)
Output:
> conf_matrix
test_labels
svm_pred 0 1 2 3 4
0 896 75 50 18 28
1 71 919 28 13 16
2 7 6 112 1 9
3 31 44 12 1023 2
4 1 5 9 0 55
> library(MLmetrics)
> Accuracy(svm_pred, test_labels)
[1] 0.8758379
> AUC(svm_pred, test_labels)
[1] 1.047074