GithubHelp home page GithubHelp logo

pombredanne / dato-predictive-service-client-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from turi-code/dato-predictive-service-client-js

0.0 1.0 0.0 47 KB

Turi Predictive Service Javascript Client

License: BSD 3-Clause "New" or "Revised" License

JavaScript 97.90% HTML 2.10%

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

Dato-Predictive-Service-Client-JS

The purpose of the Dato Predictive Service Javascript Client is to allow client-side applications to easily query Dato Predictive Services.

Installation

To install Dato Predictive Service Javascript Client, simply install with:

npm install dato-predictive-service-client-js

Requirements

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

Import

Global Import

<script src="ps-client.js" type="text/javascript"></script>

CommonJS

var PredictiveServiceClient = require('./ps-client');

AMD

define('your_script' ['ps-client'], function( PredictiveServiceClient ) {
  ...
});

Usage

Construct Client

To use the Dato Predictive Service Javascript Client, 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 imported the client object, instantiate a new client using the endpoint and API key:

//replace these values with your endpoint configuration
var endpoint = "https://your-predictive-service-endpoint.com"
var api_key = "AN_API_KEY_STRING_GOES_HERE";

// create client
var client = new PredictiveServiceClient(endpoint, api_key);

Query

To query a model that is deployed on the Predictive Service, you will need:

  • model name
  • method to query (recommend, predict, query, etc.)
  • data used to query against the model
  • your callback function

For example, the code below demonstrates how to query a recommender model, named rec, for recommendations for user Jacob Smith:

// construct data
var data = {'users': ['Jacob Smith'] };

// construct query
var request_data = {"method": "recommend", "data": data};

// query
client.query('rec', request_data, function(err, resp) {
  console.log(resp.statusCode); // status code of the response
  console.log(resp.data); // response data
});
200
{
  "uuid" : "a unique request identifier string",
  "response" : ["value1", "value2", "..."],
  "version" : 1
}

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.setTimeout(500); // 500ms

The default timeout is 10 seconds.

Results

If query is successful, the response data contains the following:

  • model response
  • uuid for this query
  • version of the model
client.query('rec', request_data, function(err, resp) {
  console.log(resp.statusCode); // status code of the response
  console.log(resp.data); // response data

  // parse respose data
  var model_response = resp.data.response;
  var uuid = resp.data.uuid;
  var version = resp.data.version;
});

model_response contains the actual model output from your query.

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 response data.

client.query('rec', request_data, function(err, resp) {
  // parse query respose data
  var model_response = resp.data.response;
  var uuid = resp.data.uuid; //uuid
});

For the feedback data, you can use any attributes or value pairs that you like.

Example:

feedback_data = { "searched_terms" : "acoommodations",
                  "num_of_clicks"  : 3 };

Now we can send this feedback data to the Predictive Service to associate this feedback with this particular query.

client.feedback(uuid, feedback_data, function(err, resp) {
  console.log(resp);
});

Optional Setters

Setter functions are provided for modification of the PredictiveServiceClient instance

// set a new endpoint
client.setEndpoint('https://new-predictive-service-endpoint.com');

// set a new API key
client.setApikey('A_NEW_API_KEY_STRING');

// set a different timeout (default is 10 seconds)
client.setTimeout(4000); //in milliseconds

More Info

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

License

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

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

Contributors

rbkreisberg avatar esoroush avatar

Watchers

 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.