[GIS] Accuracy Assesment in R

accuracyrrasterremote sensing

I there a way to calculate the accuracy of a classified image (users-, producers accuracy, Kappa) in R, assuming I have a two columns matrix. On of the columns would contain the values that came out with the classification, the other one my observed/checked values?

Best Answer

There is a confusionMatrix() function implemented in R:

library(caret) #required for confusionMatrix()

#example values
a <- c(1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1) #values from classification
b <- c(1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0)  #reference values (observed/checked) for validation 

table(a,b) #shows confusion matrix
confusionMatrix(table(a,b)) #confusion matrix with Accuracy, kappa ....

Note: confusionMatrix() only works if there no empty classes in a or b.