1

I get the following error when I try to convert my rpart model into a pmml:

Fehler in if (ff$nsurrogate[parent_ii] > 0) { :   
    Fehlender Wert, wo TRUE/FALSE nötig ist
    (Missing value where TRUE / FALSE is needed)

This error can be reproduced by the code bellow:

library(rpart)
library(pmml)
df <- structure(list(a = structure(c(15L, 1L, 13L, 8L, 11L, 25L, 6L, 
                                     24L, 27L, 9L, 2L, 18L, 28L, 14L, 5L, 17L, 20L, 21L, 16L, 7L, 
                                     22L, 19L, 23L, 26L, 3L, 10L, 12L, 4L), .Label = c("013", "018", 
                                                                                       "063", "073", "122", "173", "212", "216", "296", "355", "410", 
                                                                                       "415", "423", "428", "453", "481", "534", "586", "678", "701", 
                                                                                       "735", "746", "778", "812", "818", "855", "864", "998"), class = "factor"), 
                     y = c(1.029993, 0.95987, 0.95987, 0.95987, 0.95987, 0.95987, 
                           0.95987, 0.969903, 0.95987, 0.860644, 0.95987, 0.969903, 
                           0.900669, 0.95987, 0.95987, 0.95987, 1.12018, 0.95987, 0.95987, 
                           0.95987, 0.95987, 0.880656, 0.95987, 0.939858, 0.95987, 0.939858, 
                           0.95987, 0.95987)), row.names = c(NA, -28L), class = "data.frame")

model <- rpart(y ~ a, df, control = rpart.control(minsplit = 1, minbucket = 2, cp=-1))
pmml.rpart(model)

sessionInfo() R version 3.5.1 (2018-07-02) Platform: x86_64-redhat-linux-gnu (64-bit) Running under: Red Hat Enterprise Linux

Matrix products: default BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so

locale: [1] LC_CTYPE=de_DE.UTF-8 LC_NUMERIC=C LC_TIME=de_DE.UTF-8 LC_COLLATE=de_DE.UTF-8 LC_MONETARY=de_DE.UTF-8
[6] LC_MESSAGES=de_DE.UTF-8 LC_PAPER=de_DE.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] pmml_1.5.7 XML_3.98-1.16 rpart_4.1-13

loaded via a namespace (and not attached): [1] compiler_3.5.1 magrittr_1.5 tools_3.5.1 yaml_2.2.0 stringi_1.2.4 stringr_1.3.1

2
  • So, did our answers help? Commented Jan 30, 2019 at 23:58
  • The requirement was to grow a full tree with no pruning. That’s why we used “cp=-1”. But this was the problem to create the pmml. “cp=0” has the same effect on the tree and “pmml.rpart” worked for me. Commented Feb 1, 2019 at 8:55

2 Answers 2

0

Currently df$a is a factor, which doesn't really make sense given that the number of rows equals the number of factor levels. Fixing that with

df$a <- as.numeric(as.character(df$a))

also allows to run

pmml.rpart(model)
Sign up to request clarification or add additional context in comments.

Comments

0

Consider using the r2pmml package instead: https://github.com/jpmml/r2pmml

The conversion succeeds with the above code as-is, and the generated PMML model file is smaller, cleaner and provably correct:

library("r2pmml")
r2pmml(model, "model.pmml")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.