jpmml / jpmml-r

Java library and command-line application for converting R models to PMML
GNU Affero General Public License v3.0
33 stars 8 forks source link

ClassCastException while converting rds to pmml #3

Closed mrshanth closed 7 years ago

mrshanth commented 7 years ago

Hi,

When we tried convert rf.rds to rf.pmml, we got the following error:

Feb 07, 2017 9:53:23 PM org.jpmml.rexp.Main run
SEVERE: Failed to convert
java.lang.ClassCastException: org.jpmml.rexp.RDoubleVector cannot be cast to org.jpmml.rexp.RIntegerVector
        at org.jpmml.rexp.RandomForestConverter.encodeClassification(RandomForestConverter.java:259)
        at org.jpmml.rexp.RandomForestConverter.encodeModel(RandomForestConverter.java:95)
        at org.jpmml.rexp.RandomForestConverter.encodeModel(RandomForestConverter.java:50)
        at org.jpmml.rexp.ModelConverter.encodePMML(ModelConverter.java:78)
        at org.jpmml.rexp.ModelConverter.encodePMML(ModelConverter.java:70)
        at org.jpmml.rexp.Main.run(Main.java:149)
        at org.jpmml.rexp.Main.main(Main.java:97)

Exception in thread "main" java.lang.ClassCastException: org.jpmml.rexp.RDoubleVector cannot be cast to org.jpmml.rexp.RIntegerVector
        at org.jpmml.rexp.RandomForestConverter.encodeClassification(RandomForestConverter.java:259)
        at org.jpmml.rexp.RandomForestConverter.encodeModel(RandomForestConverter.java:95)
        at org.jpmml.rexp.RandomForestConverter.encodeModel(RandomForestConverter.java:50)
        at org.jpmml.rexp.ModelConverter.encodePMML(ModelConverter.java:78)
        at org.jpmml.rexp.ModelConverter.encodePMML(ModelConverter.java:70)
        at org.jpmml.rexp.Main.run(Main.java:149)
        at org.jpmml.rexp.Main.main(Main.java:97)

Kindly look into this issue.

vruusmann commented 7 years ago

This exception means that the value of randomForest$forest$nodepred attribute is numeric vector, when it's expected to be integer vector.

Does this problem go away if you simply change the data type of your target variable accordingly?

mydata$y = as.integer(mydata$y) # this!

rf = randomForest(y ~ ., data = mydata)
r2pmml(rf, "rf.pmml")

If that doesn't do it, then can you provide a reproducible example using some publicly available dataset? Or better yet, can you share your RDS file with me so that I could take a look into it myself?

mrshanth commented 7 years ago

The prediction variable is factor, as it is a classification exercise.

mydata$y = as.factor(mydata$y)

I cannot provide the data or the RDS file, let me replicate this error with any publicly available dataset

vruusmann commented 7 years ago

Closing as irreproducible