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.
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