0

The randomForest() function in the randomForest package very helpfully provides the confusion matrix based on out-of-bag prediction in classification.

The cforest() function in the party package does not seem to provide this information. Searching for "confusion" in the party documentation did not yield anything useful, nor did searching here. Maybe I'm overlooking something?

Is there a way to get the OOB confusion matrix for a party::cforest() classification model?

Community
  • 1
  • 1
Stephan Kolassa
  • 7,953
  • 2
  • 28
  • 48

1 Answers1

3

I took this from the party.pdf

compare, with OOB=TRUE and FALSE

set.seed(290875)
### honest (i.e., out-of-bag) cross-classification of
### true vs. predicted classes
data("mammoexp", package = "TH.data")
table(mammoexp$ME, predict(cforest(ME ~ ., data = mammoexp,
                                   control = cforest_unbiased(ntree = 50)),
                           OOB = TRUE))


                  Never Within a Year Over a Year
  Never           195            31           8
  Within a Year    57            46           1
  Over a Year      54            20           0

table(mammoexp$ME, predict(cforest(ME ~ ., data = mammoexp,
                                   control = cforest_unbiased(ntree = 50)),
                           OOB = FALSE))
  Never Within a Year Over a Year
  Never           212            22           0
  Within a Year    58            46           0
  Over a Year      54            17           3
Luis Candanedo
  • 907
  • 2
  • 9
  • 12