jpmml / r2pmml

R library for converting R models to PMML
GNU Affero General Public License v3.0
73 stars 18 forks source link

Convert NeuralNet to PMML #45

Open Clls1 opened 6 years ago

Clls1 commented 6 years ago

Hello I'm trying to extract a PMML from a model created with the neuralnet package but I have an error. I belive its due to the target variable being "GOOD + BAD" because when I try with only one of them it runs ok. However, my target is a factor so I don't know how can I resolve this issue.

Thank you!

dfGoodBad=data.frame(V1=c(.2,.1,.2,.2,.4,.3),
                    V2=c(.9,.1,.4,.5,.5,.8),
                    TARGET=factor(c('GOOD','BAD','BAD','BAD','GOOD','GOOD')))

dfGoodBad$GOOD=ifelse(dfGoodBad$TARGET=='GOOD',1,0)
dfGoodBad$BAD=ifelse(dfGoodBad$TARGET=='BAD',1,0)

nn <- neuralnet(GOOD + BAD ~ V1+V2, data = dfGoodBad, algorithm = "rprop+", linear.output = F, hidden = 3)

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

This is the error I get:

SEVERE: Failed to convert java.lang.IllegalStateException at org.jpmml.rexp.RVector.asScalar(RVector.java:56) at org.jpmml.rexp.NNConverter.encodeSchema(NNConverter.java:58) at org.jpmml.rexp.ModelConverter.encodePMML(ModelConverter.java:69) at org.jpmml.rexp.Converter.encodePMML(Converter.java:39) at org.jpmml.rexp.Main.run(Main.java:149) at org.jpmml.rexp.Main.main(Main.java:97)

Exception in thread "main" java.lang.IllegalStateException at org.jpmml.rexp.RVector.asScalar(RVector.java:56) at org.jpmml.rexp.NNConverter.encodeSchema(NNConverter.java:58) at org.jpmml.rexp.ModelConverter.encodePMML(ModelConverter.java:69) at org.jpmml.rexp.Converter.encodePMML(Converter.java:39) at org.jpmml.rexp.Main.run(Main.java:149) at org.jpmml.rexp.Main.main(Main.java:97) Error in .convert(tempfile, file, converter, converter_classpath, verbose) : 1

vruusmann commented 6 years ago

nn <- neuralnet(GOOD + BAD ~ V1+V2)

Your analysis/interpretation is correct - the R2PMML package does not support multi-output (GOOD + BAD) neural network models. If you simplify the model to single output (either GOOD or BAD), then the conversion should succeed.

This is something that should be supported.