1
$\begingroup$

Given the following:

library(rpart.plot)
iris <- read.csv("iris.csv")
my.control <- rpart.control(cp = 0, minsplit=5, xval=10)
iris.rpart <- rpart(Species ~ ., iris[,-6], method='class',
           control=my.control, parms=list(split='gini'))
iris.rpart2 <- prune(iris.rpart, cp=0.094)
table(Original = iris$Species,
      Predicted = predict(iris.rpart2, type='class'))

This yields a 3x3 matrix of original and predicted values.

Question: Using this data, how do I now create a 2x2 confusion matrix of true/false labels from the original dataset on one axis, and true/false labels from the algorithm on the other axis? This would be a sort of aggregate confusion matrix.

Desired Output:

                       True labels:
                     disagree agree
Algorithm labels:
            disagree    A       B
            agree       C       D
$\endgroup$
1
  • 1
    $\begingroup$ It's not entirely clear what you're asking. If you have a data.frame df with two columns, true membership and predicted membership, you can simply do table(df) $\endgroup$
    – Jeff
    Jan 27, 2015 at 0:48

1 Answer 1

1
$\begingroup$

The usual approach is to look at pairs of objects, where a pair exists if and only if both objects are in the same cluster. That way, you can get the usual pre/rec/f1 measures, and also rand, ARI etc. are computed from this matrix.

$\endgroup$
1
  • $\begingroup$ +1, but could you provide a simple example to illustrate this? Eg, there are N(N-1)/2 possible pairs, which presumably needs to be accounted for relative to the standard confusion matrix / AUC, etc, for say logistic reg. $\endgroup$ Jan 27, 2015 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.