Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions components/Java/pmml_predictor/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

.PHONEY: verify run

verify:
python -m json.tool < component.json > /dev/null


run:
run.sh
11 changes: 11 additions & 0 deletions components/Java/pmml_predictor/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# --- copy mlcomp jar, and (jpmml generated MOJO jar file) ----
# a) copy over ../../../../../../reflex-common/mlcomp/target/mlcomp.jar .
# b) provide the model to be used for inference along with data-set for inference

java -cp ./mlcomp.jar:./target/pmml_predictor/pmml_predictor.jar \
org.mlpiper.mlhub.components.pmml_predictor.PmmlPredictor \
--input-model <model_file> \
--samples-file <data_file> \
--output-file ./Results.csv
72 changes: 72 additions & 0 deletions components/Java/pmml_predictor/component.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"version": 1,
"engineType": "Generic",
"language": "Java",
"userStandalone": false,
"name": "pmml_predictor",
"label": "PMML Predictor",
"description": "Given a PMML model, perform predictions by reading data from a csv file and save predictions to file",
"program": "pmml_predictor.jar",
"componentClass": "org.mlpiper.mlhub.components.pmml_predictor.PmmlPredictor",
"modelBehavior": "ModelConsumer",
"useMLOps": true,
"inputInfo": [
{
"label": "samples-file",
"description": "Samples Input file, csv format. First line should contain features names",
"defaultComponent": "",
"type": "str",
"group": "data"
}
],
"outputInfo": [
{
"label": "predictions-file",
"description": "Output file containing predictions",
"defaultComponent": "",
"type": "str",
"group": "data"
}
],
"group": "Algorithms",
"arguments": [
{
"key": "input_model",
"label": "Model input file",
"description": "File to use for loading the model",
"type": "str",
"optional": true,
"tag": "input_model_path"
},
{
"key": "samples_file",
"label": "Prediction samples file",
"description": "Samples Input file, csv format. First line should contain features names",
"type": "str",
"optional": true
},
{
"key": "output_file",
"label": "Predictions output file",
"description": "File to save predictions in, if a directory is provided then the file is created inside",
"type": "str",
"optional": true
},
{
"key": "convert_unknown_categorical_levels_to_na",
"label": "Convert Unknown Categorical Levels To Na",
"description": "Convert Unknown Categorical Levels To Na",
"type": "boolean",
"default": 1,
"optional": true
},
{
"key": "convert_invalid_numbers_to_na",
"label": "Convert Invalid Numbers To Na",
"description": "Convert Invalid Numbers To Na",
"type": "boolean",
"default": 1,
"optional": true
}
]
}
217 changes: 217 additions & 0 deletions components/Java/pmml_predictor/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.mlpiper.mlhub.components.pmml_predictor</groupId>
<artifactId>pmml_predictor</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>pmml_predictor</name>
<url>http://maven.apache.org</url>

<properties>
<componentDirectory>${project.build.directory}/${project.artifactId}</componentDirectory>
</properties>

<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>

<dependency>
<groupId>net.sourceforge.argparse4j</groupId>
<artifactId>argparse4j</artifactId>
<version>0.8.1</version>
</dependency>

<dependency>
<groupId>com.parallelm.mlcomp</groupId>
<artifactId>mlcomp</artifactId>
<version>1.0</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jpmml</groupId>
<artifactId>pmml-evaluator</artifactId>
<version>1.3.5</version>
</dependency>
<dependency>
<groupId>org.jpmml</groupId>
<artifactId>pmml-model</artifactId>
<version>1.3.7</version>
<exclusions>
<exclusion>
<groupId>org.jpmml</groupId>
<artifactId>pmml-agent</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>javax.activation-api</artifactId>
<version>1.2.0</version>
</dependency>

</dependencies>

<profiles>
<profile>
<id>production</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<finalName>${project.artifactId}</finalName>
<outputDirectory>${componentDirectory}</outputDirectory>
<archive>
<manifest>
<mainClass>
org.mlpiper.mlhub.components.pmml_predictor.PmmlPredictor
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>

<executions>
<execution>
<id>verify-component-json</id>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<workingDirectory>${project.basedir}</workingDirectory>
<executable>make</executable>
<commandlineArgs>verify</commandlineArgs>
</configuration>
</execution>
<execution>
<id>copy-component-json</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<workingDirectory>${project.basedir}</workingDirectory>
<executable>cp</executable>
<commandlineArgs>component.json ${componentDirectory}</commandlineArgs>
</configuration>
</execution>
<execution>
<id>create-init-dot-py</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<workingDirectory>${project.basedir}</workingDirectory>
<executable>touch</executable>
<commandlineArgs>${componentDirectory}/__init__.py</commandlineArgs>
</configuration>
</execution>
<execution>
<id>gen-component-tar</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<workingDirectory>${project.build.directory}</workingDirectory>
<executable>tar</executable>
<commandlineArgs>cvf ${project.name}.tar ${project.name}</commandlineArgs>
</configuration>
</execution>

</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.12</version>
</dependency>
</dependencies>
</plugin>

</plugins>
</build>
</profile>
<profile>
<id>test</id>
<properties>
<build.profile.id>test</build.profile.id>
<skip.integration.tests>false</skip.integration.tests>
<skip.unit.tests>true</skip.unit.tests>
<failIfNoTests>false</failIfNoTests>
</properties>
</profile>
</profiles>
</project>
13 changes: 13 additions & 0 deletions components/Java/pmml_predictor/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

MODEL=$1
DATA_FILE=$2

java -cp ./target/pmml_predictor/pmml_predictor.jar \
org.mlpiper.mlhub.components.pmml_predictor.PmmlPredictor \
--convert-invalid-numbers-to-na true \
--convert-unknown-categorical-levels-to-na true \
--input-model $MODEL \
--samples-file $DATA_FILE \
--output-file /tmp/predictions.csv

Loading