Description Usage Arguments Details Value Author(s) Examples
... and expand inbag matrix and training target vector to compute FC for a test set.
1 | Xtestmerger(X,test,inbag=NULL,y=NULL)
|
X |
X , training set data.frame used to train a random forest model |
test |
test, a test set data.frame which feature contributions should be computed for |
inbag |
matrix of inbag sampling to expande with training set, which is set OOB for any tree |
y |
random forest target vector, which is set to first value for observation |
Xtestmerger is a low-level function to merge a test set with X training set. There can be no names, column class, column number mismatch. Moreover any level in any factor of test must be present in X, as RF/forestFloor cannot score a unknown factor level / category.
List of merged bigX, bigInbag and bigy. The two latter may be NULL if not provided.
Soren Havelund Welling
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | library(randomForest)
library(forestFloor)
#X y could be a training set
X = data.frame(numeric = c(1,5,2,7,-4.3),
factor1 = factor(c("jim","freddy","marley","marley","alfred")),
factor2 = factor(c("jill","ann","liz","leila","vicky")))
y = factor(1:5)
set.seed(1)
rf = randomForest(X,y,keep.inbag=TRUE,ntree=7)
#should not raise any error
test = data.frame(numeric = rnorm(5),
factor1 = factor(c("jim","jim","jim","freddy","freddy")),
factor2 = factor(c("jill","jill","vicky","leila","vicky"))
)
out = Xtestmerger(X,test,inbag=rf$inbag,y=y)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.