GithubHelp home page GithubHelp logo

jpmml / jpmml-postgresql Goto Github PK

View Code? Open in Web Editor NEW
11.0 3.0 1.0 165 KB

PMML evaluator library for the PostgreSQL database (http://www.postgresql.org/)

License: GNU Affero General Public License v3.0

Java 100.00%

jpmml-postgresql's Introduction

JPMML-PostgreSQL Build Status

PMML evaluator library for the [PostgreSQL database] (http://www.postgresql.org/).

Features

Prerequisites

Overview

A working JPMML-PostgreSQL setup consists of a library JAR file and a number of model JAR files. The library JAR file is centered around the utility class org.jpmml.postgresql.PMMLUtil, which provides PL/Java compliant utility methods for handling most common PMML evaluation scenarios. A model JAR file contains a model launcher class and a corresponding PMML resource. Model JAR files can be added, replaced and/or removed on the go using PL/Java SQL commands. All changes take effect immediately. There is no need to modify PostgreSQL database configuration or restart the service.

The main responsibility of a model launcher class is to formalize the "public interface" of a PMML resource. Every PL/Java function must be backed by a public static method that takes a PostgreSQL tuple as an argument, and returns either a PostgreSQL scalar or a PostgreSQL tuple as a result.

The example model JAR file contains a DecisionTree model for the "iris" dataset. This model is exposed in two ways. First, the model launcher class org.jpmml.postgresql.DecisionTreeIris defines two functions that return the PMML target field ("Species") together with four output fields ("Predicted_Species", "Probability_setosa", "Probability_versicolor", "Probability_virginica") as a PostgreSQL tuple. Second, the model launcher class org.jpmml.postgresql.DecisionTreeIris_Species defines two functions that return the PMML target field ("Species") as a PostgreSQL character type. The installation and removal of functions is completely automated using an SQL deployment descriptor mechanism.

Installation

Enter the project root directory and build using [Apache Maven] (http://maven.apache.org/):

mvn clean install

The build produces two JAR files:

  • pmml-postgresql/target/pmml-postgresql-runtime-1.0-SNAPSHOT.jar - Library uber-JAR file. It contains the classes of the library JAR file pmml-postgresql/target/pmml-postgresql-1.0-SNAPSHOT.jar, plus all the classes of its transitive dependencies.
  • pmml-postgresql-example/target/pmml-postgresql-example-1.0-SNAPSHOT.jar - Example model JAR file.

Usage

Library

Installation

Install the library uber-JAR file:

SELECT sqlj.install_jar('file:///tmp/pmml-postgresql-runtime-1.0-SNAPSHOT.jar', 'jpmml', false);

The PL/Java function sqlj.install_jar takes three arguments:

  1. The URL of the JAR file.
  2. A symbolic name after which this JAR file is later known for.
  3. A flag indicating if this JAR file contains an executable SQL deployment descriptor ("BEGIN INSTALL ...").

Add the library uber-JAR file to the classpath of the target schema:

SELECT sqlj.set_classpath('public', 'jpmml');
Removal

Remove the library uber-JAR file:

SELECT sqlj.remove_jar('jpmml', false);

The PL/Java function sqlj.remove_jar takes two arguments:

  1. The symbolic name of the JAR file.
  2. A flag indicating if this JAR file contains an executable SQL deployment descriptor ("BEGIN REMOVE ...").

PL/Java examines all classpaths and propagates the removal if appropriate.

Example model

Installation

Install the example model JAR file:

SELECT sqlj.install_jar('file:///tmp/pmml-postgresql-example-1.0-SNAPSHOT.jar', 'DecisionTreeIris', true);

Behind the scenes, the SQL deployment descriptor orders the creation of two composite types and two functions as follows:

CREATE TYPE iris_request AS (
	"Sepal_Length" double precision,
	"Sepal_Width" double precision,
	"Petal_Length" double precision,
	"Petal_Width" double precision
);
CREATE TYPE iris_response AS (
	"Species" varchar,
	"Predicted_Species" varchar,
	"Probability_setosa" double precision,
	"Probability_versicolor" double precision,
	"Probability_virginica" double precision
);
CREATE FUNCTION DecisionTreeIris(iris_request) RETURNS iris_response
	AS 'org.jpmml.postgresql.DecisionTreeIris.evaluate'
	LANGUAGE java;
CREATE FUNCTION DecisionTreeIris("Sepal_Length" double precision, "Sepal_Width" double precision, "Petal_Length" double precision, "Petal_Width" double precision) RETURNS iris_response
	AS 'org.jpmml.postgresql.DecisionTreeIris.evaluate'
	LANGUAGE java;
CREATE FUNCTION DecisionTreeIris_Species(iris_request) RETURNS varchar
	AS 'org.jpmml.postgresql.DecisionTreeIris_Species.evaluate'
	LANGUAGE java;
CREATE FUNCTION DecisionTreeIris_Species("Sepal_Length" double precision, "Sepal_Width" double precision, "Petal_Length" double precision, "Petal_Width" double precision) RETURNS varchar
	AS 'org.jpmml.postgresql.DecisionTreeIris_Species.evaluate'
	LANGUAGE java;

Add the example model JAR file to the classpath of the target schema. The classpath is constructed by concatenating the symbolic name of the library uber-JAR file with the symbolic names of model JAR files (using comma : as a path separator character):

SELECT sqlj.set_classpath('public', 'jpmml:DecisionTreeIris');
Usage

Predicting the iris species together with the calculated probabilities for each target category:

SELECT (DecisionTreeIris(7, 3.2, 4.7, 1.4)).*;

Result:

  Species   | Predicted_Species | Probability_setosa | Probability_versicolor | Probability_virginica 
------------+-------------------+--------------------+------------------------+-----------------------
 versicolor | versicolor        |                  0 |               0.907407 |             0.0925926

Predicting the iris species:

SELECT DecisionTreeIris_Species(7, 3.2, 4.7, 1.4);

Result:

 decisiontreeiris_species 
-------------------------
 versicolor
Removal

Remove the example model JAR file:

SELECT sqlj.remove_jar('DecisionTreeIris', true);

Behind the scenes, the SQL deployment descriptor orders the deletion of two composite types and two functions as follows:

DROP FUNCTION DecisionTreeIris_Species(double precision, double precision, double precision, double precision);
DROP FUNCTION DecisionTreeIris_Species(iris_request);
DROP FUNCTION DecisionTreeIris(double precision, double precision, double precision, double precision);
DROP FUNCTION DecisionTreeIris(iris_request);
DROP TYPE iris_response;
DROP TYPE iris_request;

License

JPMML-PostgreSQL is dual-licensed under the [GNU Affero General Public License (AGPL) version 3.0] (http://www.gnu.org/licenses/agpl-3.0.html) and a commercial license.

Additional information

Please contact [[email protected]] (mailto:[email protected])

jpmml-postgresql's People

Contributors

vruusmann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

edwardt

jpmml-postgresql's Issues

NullpointerException while using code with Neural Network Model

Hi,

I am beginner in this Jpmml and i was testing my neural network model using this jpmml-postgresql i changed deployment descriptor and and code accordingly to my neural network model i.e,. i added the input and output fields as per my requirement and while running the select command by passing the inputs i am getting Error: java.lang.NullPointerException. do i need to change anything to use this code to work with Neural Network models. can you please help me out

thanks in advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.