Git Product home page Git Product logo

dato-predictive-service-client-java's Introduction

Dato Predictive Service Java Client

The purpose of the Dato Predictive Service Java Client library is to allow Java applications to easily query Dato Predictive Services.

To use the Dato Predictive Service Java Client library, simply add this dependency to your Maven POM file:

<dependency>
  <groupId>com.dato</groupId>
  <artifactId>predictive-service-client</artifactId>
  <version>1.0</version>
</dependency>

You can also download the artifact: Maven Search

Requirements

  • Dato Predictive Service, launched by GraphLab-Create >= 1.4 installation

Usage

Construct Client

To use the Dato Predictive Service Java Client library, first you need to obtain the following information from a running Dato Predictive Service:

  • Predictive Service CNAME or DNS name (endpoint)
  • API key from the Predictive Service

Once you have obtained the above information, simply construct the PredictiveServiceClient:

import com.dato.deploy.PredictiveServiceClient;

PredictiveServiceClient client = new PredictiveServiceClient("CNAME or DNS name",
                           "API key", true); // enabled SSL certificate verification

To enable SSL certificate verification for this Predictive Service, set the last parameter of the PredictiveServiceClient constructor to true. However, if you Predictive Service is launched with a self-signed certificate or without certificate, please set to false the last parameter of the constructor.

The PredictiveServiceClient can also be constructed by using a Predictive Service client configuration file.

PredictiveServiceClient client = new PredictiveServiceClient("path to config file");

Setup Request

To query your Predictive Service with this client, you need to create a simple JSON object. We use json-simple to perform JSON operations.

First add the method name that will be used to query your deployed model.

import org.json.simple.JSONObject;

JSONObject request = new JSONObject();
request.put("method", "recommend");

Then construct the query data to your model and add it to the request JSONObject.

For example,

JSONObject data = new JSONObject();
data.put("users", new ArrayList<String>(Arrays.asList("new", "test")));

// add the data object to reqest
request.put("data", data);

The request needs to be JSON serializable in order to be used to query the Predictive Service. Therefore, make sure all the objects that you add to the request are all JSON serializable.

Notes

  • Different models could support different query methods (recommend, predict, query, etc.) and different syntax and format for data. You will need to know the supported methods and query data format before querying the model.

Set timeout

To change the request timeout when querying the Predictive Service, use the following:

client.setQueryTimeout(500); // 500ms

The default timeout is 10 seconds.

Query

To query your deployed model on the Predictive Serivce, simply do the following:

import com.dato.deploy.PredictiveServiceClientResponse;

PredictiveServiceClientResponse response = client.query("you model name here",
                                                        request);

Results

To obtain the query results from the Predictive Service, simply use the returned response:

import org.json.simple.JSONObject;
JSONObject results = response.getResult();

getResult() returns a JSONObject that contains the query results of your model from the PredictiveService.

Send feedback

Once you get the query result, you can submit feedback data corresponding to this query back to the Predictive Service. This feedback data can be used for evaluating your current model and training future models.

To submit feedback data corresponding to a particular query, you will need the UUID of the query. The UUID can be easily obtained from the query result.

String uuid = results.get("uuid");

For the feedback data, you can use any attributes or value pairs that you like. However, it must be contained within a JSONObject and must be JSON serializable.

Example:

JSONObject feedback_request = new JSONObject();
feedback_request.put("searched_terms", "accommodations");
feedback_request.put("num_of_clicks", 3);

With that JSONObject constructed above, we can send this JSONObject to the Predictive Service to associate this feedback with a particular query.

PredictiveServiceClientResponse response = client.feedback(uuid,
                                                           feedback_request);

More Info

For more information about the Dato Predictive Service, please read the API docs and userguide.

License

The Dato Predictive Service Client is provided under the 3-clause BSD license.

dato-predictive-service-client-java's People

Contributors

takeon8 avatar

Watchers

 avatar  avatar

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.