r - Create a confusion matrix from a dataframe -
r - Create a confusion matrix from a dataframe -
i have info frame called conf_mat
2 columns including predicted values , reference values in each objects. have 20 objects in dataframe.
dput(conf_mat) structure(list(predicted = c(100, 200, 200, 100, 100, 200, 200, 200, 100, 200, 500, 100, 100, 100, 100, 100, 100, 100, 500, 200 ), reference = c(600, 200, 200, 200, 200, 200, 200, 200, 500, 500, 500, 200, 200, 200, 200, 200, 200, 200, 200, 200)), .names = c("predicted", "reference"), row.names = c(na, 20l), class = "data.frame")
i want create confusion matrix out of table kind of construction filled in conf_mat
dataframe. allow me compute accuracu assessment of classification. help.
100 200 300 400 500 600 100 na na na na na na 200 na na na na na na 300 na na na na na na 400 na na na na na na 500 na na na na na na 600 na na na na na na
1) seek following:
table(conf_mat)
2) if want forcefulness levels 100, 200, ..., 600 appear:
conf_mat_tab <- table(lapply(conf_mat, factor, levels = seq(100, 600, 100)))
3) seek this:
library(caret) confusionmatrix(conf_mat_tab) # conf_mat_tab (2)
which gives:
confusion matrix , statistics reference predicted 100 200 300 400 500 600 100 0 9 0 0 1 1 200 0 6 0 0 1 0 300 0 0 0 0 0 0 400 0 0 0 0 0 0 500 0 1 0 0 1 0 600 0 0 0 0 0 0 overall statistics accuracy : 0.35 95% ci : (0.1539, 0.5922) no info rate : 0.8 p-value [acc > nir] : 1 kappa : 0.078 mcnemar's test p-value : na statistics class: class: 100 class: 200 class: 300 class: 400 class: 500 class: 600 sensitivity na 0.3750 na na 0.3333 0.00 specificity 0.45 0.7500 1 1 0.9412 1.00 pos pred value na 0.8571 na na 0.5000 nan neg pred value na 0.2308 na na 0.8889 0.95 prevalence 0.00 0.8000 0 0 0.1500 0.05 detection rate 0.00 0.3000 0 0 0.0500 0.00 detection prevalence 0.55 0.3500 0 0 0.1000 0.00 balanced accuracy na 0.5625 na na 0.6373 0.50
r data.frame confusion-matrix
Comments
Post a Comment