jpmml / r2pmml

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

Add support for the `isofor` package #34

Open jwveld opened 6 years ago

jwveld commented 6 years ago

When trying to convert an Iforest model I get the following errors.

nov 30, 2017 3:06:55 PM org.jpmml.rexp.Main run INFO: Parsing RDS.. nov 30, 2017 3:06:56 PM org.jpmml.rexp.Main run INFO: Parsed RDS in 332 ms. nov 30, 2017 3:06:56 PM org.jpmml.rexp.Main run INFO: Initializing default Converter nov 30, 2017 3:06:56 PM org.jpmml.rexp.Main run INFO: Initialized org.jpmml.rexp.IForestConverter nov 30, 2017 3:06:56 PM org.jpmml.rexp.Main run INFO: Converting.. nov 30, 2017 3:06:56 PM org.jpmml.rexp.Main run SEVERE: Failed to convert java.lang.IllegalArgumentException: xcols at org.jpmml.rexp.RVector.getValue(RVector.java:104) at org.jpmml.rexp.RVector.getValue(RVector.java:80) at org.jpmml.rexp.IForestConverter.encodeSchema(IForestConverter.java:59) at org.jpmml.rexp.ModelConverter.encodePMML(ModelConverter.java:74) 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.IllegalArgumentException: xcols at org.jpmml.rexp.RVector.getValue(RVector.java:104) at org.jpmml.rexp.RVector.getValue(RVector.java:80) at org.jpmml.rexp.IForestConverter.encodeSchema(IForestConverter.java:59) at org.jpmml.rexp.ModelConverter.encodePMML(ModelConverter.java:74) 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) Error in .convert(tempfile, file, converter, converter_classpath, verbose) : 1 In addition: Warning message: running command '"java" -cp "J:/R_werk/R/library/r2pmml/java/guava-20.0.jar;J:/R_werk/R/library/r2pmml/java/istack-commons-runtime-3.0.5.jar;J:/R_werk/R/library/r2pmml/java/jaxb-core-2.3.0.jar;J:/R_werk/R/library/r2pmml/java/jaxb-runtime-2.3.0.jar;J:/R_werk/R/library/r2pmml/java/jcommander-1.48.jar;J:/R_werk/R/library/r2pmml/java/jpmml-converter-1.2.6.jar;J:/R_werk/R/library/r2pmml/java/jpmml-r-1.2.20.jar;J:/R_werk/R/library/r2pmml/java/jpmml-xgboost-1.2.3.jar;J:/R_werk/R/library/r2pmml/java/pmml-agent-1.3.8.jar;J:/R_werk/R/library/r2pmml/java/pmml-model-1.3.8.jar;J:/R_werk/R/library/r2pmml/java/pmml-model-metro-1.3.8.jar;J:/R_werk/R/library/r2pmml/java/pmml-schema-1.3.8.jar;J:/R_werk/R/library/r2pmml/java/slf4j-api-1.7.25.jar;J:/R_werk/R/library/r2pmml/java/slf4j-jdk14-1.7.25.jar" org.jpmml.rexp.Main --rds-input "C:\Users\ADMINV~2\AppData\Local\Temp\3\RtmpKAvfFn\r2pmml-3ee2c512c6347.rds" --pmml-output "text.pmml"' had status 1

vruusmann commented 6 years ago

Reproducible example?

java.lang.IllegalArgumentException: xcols at org.jpmml.rexp.RVector.getValue(RVector.java:104)

Your iForest model object does not have the xcols element. I've seen the same (or very similar) exception before, and IIRC, the cause was that the training dataset contained non-numeric features.

Since the iForest model object is incomplete/invalid, you shouldn't be able to use it for prediction in R either. Can you verify, the IsolationForest::AnomalyScore function should fail with an error?

jwveld commented 6 years ago

Hi Villu,

Thanks for your reply I’m using the isofor package in R. And it scores nicely.

IsolationForest::AnomalyScore = not a command the package knows.

Jan

Package: isofor Type: Package Title: Isolation Forest Anomaly Detection Version: 0.1.3 Authors@R: c( person("Eric", "Graves", email = "gravcon@gmail.com", role = "cre"), person("Ignat", "Drozdov", email = "idrozdov@beringresearch.com", role = "aut")) Description: One efficient way of performing outlier detection in high-dimensional datasets is to use random forests. The isofor ‘isolates’ observations by randomly selecting a feature and then randomly selecting a split

Op 1 dec. 2017, om 05:53 heeft Villu Ruusmann notifications@github.com het volgende geschreven:

Reproducible example?

java.lang.IllegalArgumentException: xcols at org.jpmml.rexp.RVector.getValue(RVector.java:104)

Your iForest model object does not have the xcols element. I've seen the same (or very similar) exception before, and IIRC, the cause was that the training dataset contained non-numeric features.

Since the iForest model object is incomplete/invalid, you shouldn't be able to use it for prediction in R either. Can you verify, the IsolationForest::AnomalyScore function should fail with an error?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jpmml/r2pmml/issues/34#issuecomment-348401028, or mute the thread https://github.com/notifications/unsubscribe-auth/AH4hGWFkObqfVLVZ1q79Ut7vSN3Wvp6Qks5s74ZLgaJpZM4Qwm3P.

vruusmann commented 6 years ago

I’m using the isofor package in R. And it scores nicely.

The r2pmml package only knows about isolation forest (IF) models that have been trained using the IsolationForest package: https://r-forge.r-project.org/R/?group_id=479

You're using an alternative IF implementation, and it is no wonder that r2pmml can't understand what's going on (the model type is determined based on its R class name, and looks like both IF implementations are producing iForest classes then?).

For your information, the full list of supported R packages/model types is listed in the README file of the JPMML-R library: https://github.com/jpmml/jpmml-r#features

vruusmann commented 6 years ago

Will try to look into functional differences between IsolationForest and isofor packages mid-December, when I'm back from my very-very long business trip.

jwveld commented 6 years ago

Hello Villu,

Thank you.. I will try the IsolationForest implementation.

And curious about you findings concerning isofor.

Jan

Op 1 dec. 2017, om 14:59 heeft Villu Ruusmann notifications@github.com het volgende geschreven:

Will try to look into functional differences between IsolationForest and isofor packages mid-December, when I'm back from my very-very long business trip.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jpmml/r2pmml/issues/34#issuecomment-348501374, or mute the thread https://github.com/notifications/unsubscribe-auth/AH4hGUqnCxHKyAR8RPUiIu0--eMyh36cks5s8AYygaJpZM4Qwm3P.