Closed edumucelli closed 7 years ago
The order of function parameters for the r2pmml.ranger()
function was changed between 0.13.0 and 0.13.1 versions:
https://github.com/jpmml/r2pmml/commit/15c432278ff7fe8effac2100452ed02eb355c01a
According to sessionInfo()
, you're currently using r2pmml
version 0.12.3. Your problem should be solved simply by upgrading to the latest version:
library("devtools")
remove.packages("r2pmml")
install_github(repo = "jpmml/r2pmml")
The variable.levels
argument is supposed to provide complete set of category levels for categorical features (as the ranger
model object does not contain this information). So, you need to do sapply(train_x, levels)
. If your dataset does not contain any categorical features, then you may leave it empty.
Also, you might want to consider upgrading to ranger
version 0.7.0.
Sorry, just realized that your issue is about passing variable.levels
in a situation where the ranger
function is invocated via the caret package, not directly.
In this case, you need to attach the variable.levels
field directory to the train$finalModel
object:
model_fit = train_with_matrix(train_x, train_y, method)
model_fit$finalModel$variable.levels = sapply(train_x, levels) # THIS
r2pmml(model_fit, paste0(method, ".benchmark.", NCOL, ".pmml"))
I'm reopening this issue in order to figure out a more elegant way of "decorating" caret-trained model objects with extra information.
It affects more model types, not just the ranger
model type. For example, there needs to be an easy way to decorate caret-trained xgb.Booster
objects with feature map information.
Now it's possible to simply do:
model_fit = train_with_matrix(train_x, train_y, method)
r2pmml(model_fit, paste0(method, ".benchmark.", NCOL, ".pmml"), variable.levels = sapply(train_x, levels))
Wow, great! Thanks for the quickness and the responsiveness!
It's not working for me for neural networks:
mynn <- nnet(Churn ~ ., data=trainNN, size=3, decay=1.0e-5, maxit=50, softmax = TRUE)
mynn$variable.levels <- lapply(trainNN, function(x){ if(is.factor(x)) { levels(x) } else { NULL }})
After:
r2pmml(mynn,"churn_nnet_pmml.xml", verbose = TRUE, variable.levels = mynn$variable.levels)
I have an error:
Error in decorate.default(x, ...) :
unused argument (variable.levels = list(X.area.code.408 = NULL, X.area.code.510 = NULL, X.international.plan.1 = NULL, X.number.vmail.messages. = NULL, X.total.day.charge. = NULL, Churn = NULL))
@EwelinaEwelina The "decoration" is different for each R model type. What works for ranger
(this original issue) does not work for nnet
(your issue).
The r2pmml::r2pmml()
function does all the necessary decoration work behind the scenes automatically, so there is no need to assist it in any way.
Hi Villu,
I have been facing a different behavior between the conversion of "rf" and "ranger", the latter fails with the following error
variable.levels
is not been taking into consideration, though. However it works normally to convert arf
model with the same configuration. Bellow is the reproducible codeAnd here is the
sessionInfo
I guess I am missing something on the
variable.levels
which I have not been able to figure out. Thank you in advance for any tips on that problem. Cheers!