This question is similar to some other questions on Stackoverflow (here, here and here), but different enough so that I cannot extrapolate those answers to my case.
I have a function in which I fit a C5.0 model and than try to plot the model.
train_d <- globald[train_ind,c(features,21)]
model <- C5.0(binclass ~ .,data=train_d,trials=10)
binclass
is a column name in my training/test data (globald is a dataframe from which I subset rows with _ind
indices and columns c(3:12,21)
, where column 21 is named binclass
). Fitting works well. However, when I also add the line
plot(model,trial=0)
then I get the following error: Error in is.data.frame(data) : object 'train_d' not found
.
How is it possible that when fitting the model, train_d
is found and used correctly, but while plotting, train_d
is nowhere to be found? And, any suggestion of how to solve this issue. Namespaces in [r] remain a mystery to me.
A minimal running example is the following:
f <- function(){
library(C50)
set.seed(1)
class = c(1,2)
d <- data.frame(feature1 = sample(1:10,10,replace=TRUE), feature2 = 1:10, binclass = class)
d$binclass <- as.factor(d$binclass)
model <- C5.0(binclass ~ ., data=d)
plot(model)
}
Calling f()
results in the following error: Error in is.data.frame(data) : object 'd' not found
Edit: As per the answer from MrFlick, it seems that the cause of this problem is a bug in the C5.0 code. There are some workarounds are indicated by Pascal and MrFlick.