Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract Accuracy from caret's confusionMatrix?

Tags:

r

I'm trying to just extract the Accuracy value from the confusionMatrix() output -- I've tried using the following:

    cl <- train.data[,1]
    knn.res <- knn.cv(train.data[,c(2:783)], cl, k = i, algorithm = "cover_tree")
    confus.knn.res <- confusionMatrix(knn.res, train.data[,1])
    confus.knn.res
    k.accuracy[which(k.accuracy[,2]==i),2] <- confus.knn.res$Accuracy

though just calling it as $Accuracy doesn't seem to work.

like image 855
orange1 Avatar asked Sep 05 '25 02:09

orange1


1 Answers

One of the values of confusionMatrix() object is overall -- the first index of overall is the accuracy value. Therefore, it can be called as confus.knn.res$overall[1].

like image 77
orange1 Avatar answered Sep 07 '25 09:09

orange1