In my data, I've been able to create a confusion matrix:
cm<- table(predict(model,newdata=as.matrix(dat2[,-(1:2)])),dat2$r)
cm
## 0 1 2 3 4 5 6 7
## 0 126 0 0 0 0 0 0 0
## 1 3 483 7 1 12 11 8 7
## 2 1 14 1413 1 60 47 53 46
## 3 0 0 0 90 0 0 0 0
## 4 27 92 144 5 6566 308 500 236
## 5 4 24 63 3 129 1899 201 35
## 6 2 14 40 0 82 100 1994 40
## 7 0 0 0 0 0 0 0 375
How do I find the accuracy of this confusion matrix? Or do 1 - error rate so how do I find the error rate? Thanks guys.
For the accuracy
sum(diag(cm))/sum(cm)
where diag
is all of the values across the diagonal of your matrix.