Closed wendywangwwt closed 6 years ago
Thanks for the reproducible example.
The exception that I'm seeing is the following:
Exception in thread "main" java.lang.IllegalArgumentException
at org.jpmml.xgboost.RegTree.encodePredicate(RegTree.java:169)
The R2PMML/JPMML-R stack has passed the control to the JPMML-XGBoost library, which fails because it encounters an unsupported feature data type.
XGBoost can handle integer
and float
features. However, when Caret pre-processing is involved, then the feature type is promoted from float
to double
.
In principle, Caret pre-processing can be combined with any R model type, including the xgb.Booster
model type. The R2PMML/JPMML-R stack should simply perform an explicit downcast from double
to float
here in order to make the JPMML-XGBoost library happy. This is a simple fix that should become available in a couple of days time.
I get an error when converting an xgboost model with variable transformations into pmml while the same process for a linear regression works:
library(pmml)
library(pmmlTransformations)
library(xgboost)
data(audit)
audit <- audit[, c("Age", "Deductions", "Hours", "Income", "Sex")]
audit$Sex <- as.character(audit$Sex)
audit$Income <- ifelse(audit$Income > 40000,
1,
0
)
auditBox <- WrapData(audit[, c("Age", "Deductions", "Hours", "Sex", "Income")])
t <- list()
m <- data.frame(c("Sex","string","Male"),
c("d_sex2","integer",1))
t[[1]] <- m
auditBox <- MapXform(auditBox,xformInfo=t,defaultValue=c(0),
mapMissingTo="0")
#######################################
############ LM ##################
fit<-lm(Income~.,data=auditBox$data[, c("Age", "Deductions", "Hours", "d_sex2", "Income")])
fit_pmml = pmml(fit,transforms=auditBox)
#######################################
############ XGBOOST ##################
tablonXg <- xgb.DMatrix(as.matrix(auditBox$data[, c("Age", "Deductions", "Hours", "d_sex2")]),
label = audit[, "Income"]
)
fit_xg <- xgb.train(data = tablonXg,
nrounds = 100,
objective = "binary:logistic",
eval_metric = "auc",
verbose = FALSE
)
xgb.dump(fit_xg, "fitmodel")
xg_pmml = pmml(fit_xg,
transforms=auditBox,
inputFeatureNames = c("Age", "Deductions", "Hours", "d_sex2"),
outputLabelName = "Income",
xgbDumpFile = "fitmodel"
)
Error in .pmmlLocalTransformations(field, transforms, ltNode) :
object 'ltNode' not found
In addition: Warning message:
In pmml.xgb.Booster(fit_xg, transforms = auditBox, inputFeatureNames = c("Age", :
No output categories given; regression model assumed.
@asuskitty Your code example is about pmml
and pmmlTransformations
packages, while this is the r2pmml
package.
Please switch from pmml
to r2pmml
.
Hi,
I tried the example code and combined the example of preProcess option and the example of xgboost. However, I got an error. Is it because xgboost wrapper doesn't support the proProcess option or I made some mistake?
The reproducible code is here:
and the error I got is:
I saw issue 40 and checked my java version:
Thank you!