2

I am fitting a cforest with the optional argument caseweights, which is a double matrix with ncol(caseweights)== number of trees in my random forest and nrow(caseweights)= number of observations. Furthermore I am normalizing them so that the colSums are equal to one. However when I want to compare my OOB predictions with the true response, I always get the following error:

Error in RET@prediction_weights(newdata = newdata, mincriterion = mincriterion, : cannot compute out-of-bag predictions for observation number 1

I have looked up the C source code on github, nevertheless couldn't find out why I it does not work.

(The same error also occurs if I use ''standard'' weights i.e. a vector of length == number of observations, which is used just for sampling)

What I am doing wrong ?

Here is a reproducible example:

install.packages('party')
require('party')
head(iris)
weights<-rep(1,nrow(iris))
weights[iris$Species=='virginica']<-2
#normalize
weights<-weights/sum(weights) 
ntree<-100
#generate double matrix of caseweights
caseweights<-matrix(rep(weights,ntree),ncol=ntree)
colSums(caseweights)
#fit forest
f <- cforest(Species ~ ., data = iris,controls = cforest_unbiased(ntree=ntree,mtry=3,trace=TRUE),weights=caseweights)
#check out of bag cross classification
table(iris$Species,Predict(f,OOB=TRUE)) #throws error

Thank you very much for your help.

Gopal Bhuva
  • 654
  • 2
  • 13
  • 20
franzfranz
  • 23
  • 4

1 Answers1

2

Well, none of your weights is zero, so there are no out-of-bag observations and this is what the error message correctly tells you. Btw, party is not hosted on github but on R-forge.

Torsten

  • 1
    For Torsten: You can use the read-only mirror of CRAN on Github to view the source code of CRAN packages with the usual highlighting etc. https://github.com/cran/party For franzfranz: The party(kit) packages are developed on R-Forge where you can obtain devel versions etc., see https://R-Forge.R-project.org/R/?group_id=1306 and https://R-Forge.R-project.org/R/?group_id=261 – Achim Zeileis Apr 20 '18 at 12:26