Class: PredictScript

PredictScript


new PredictScript()

PredictScript is a JavaScript library for building and serving various types of predictive models:
  • Binary classification (true/false outcome):
    1. Call predict to estimate the probability of an event ocurring.
    2. Call label to set the actual outcome of a prediction returned by the previous call. This call updates the model using the features provided to predict.
  • Ranking:
    1. Call rank in order to get entry rankings but also to collect data and train the model. This must be called even before a model is trained, in order to build a training data set. Initially the call will return null predictions, but once enough training data exists, the model will be automatically trained and begin returning rankings.
    2. Call labelRankedEntries to set the relevance of an entry returned by the previous call. This data will be used to re-train the model.

Methods


config(apiKey)

Configures the library. Must be called after the library is loaded, before it can be used to correctly record predictions and labels.
Parameters:
Name Type Description
apiKey string Your API key.

predict(modelName, features [, options])

Asynchronous request for prediction. The features are used to make a prediction. Additionally, the features become a training example once paired with a label call.
Parameters:
Name Type Argument Default Description
modelName string The name of the model to use.
features Object An object of features to use for prediction. The feature property names should be consistent across all predict calls to a model. Missing properties are treated the same as having a null value. The value types must be numeric (float), categorical (string), or another object.
options Object <optional>
{} An object of options to use for prediction. Reserved.
Returns:
Promise object which, when fulfilled, is an anonymous object with properties described by predictReturn.
Type
Promise.<predictReturn>

label(predictionId, outcome)

Sets a label outcome for a prediction. The goal of a model is to accurately predict an outcome given a feature set. For instance, if you want to predict "Will the user make a purchase?", you call predictscript.label(predictionId, true) when the user completes a purchase.
Parameters:
Name Type Description
predictionId string The id property of the prediction object returned by predict.
outcome boolean The outcome label to apply, either true or false.

rank(modelName, contextFeatures, entriesToRank)

Asynchronous request for ranking a set of entries. Each entry is specified as a required ID plus a set of features for each entry. The context features are merged with the features of each entry and the resulting union of features is evaluated against the model. The entries are then ranked based on the returned model probability.
Parameters:
Name Type Description
modelName string The name of the model to use.
contextFeatures Object The context features to merge with the features of each entry. These are typically user requested features.
entriesToRank Array.<Object> The set (array) of entries to rank. Each entry must have a client entryId property whose value is a unique string across all entries, plus a set of feature properties. The feature property names should be consistent across all rank calls to a given model. Missing properties are treated the same as having a null value. The value types must be numeric (float), categorical (string) or another object.

Features specified in each entry will take precedence over context features, if there are feature name collisions between the two. This can be used to override context feature values on a per entry basis.

Properties
Name Type Argument Description
entryId string The required unique ID of each entry. This is considered an opaque client side ID which will be returned back to the caller. It must be unique across all entries or the server will return an error.
feature number | string <repeatable>
The features as property names and values, where feature is the actual feature name.
Returns:
Promise which, when fulfilled, is an anonymous object with properties described by rankReturn.
Type
Promise.<rankReturn>

labelRankedEntries(predictionId, entries)

Labels a set of entries returned by a call to rank. The relevance is typically the result of a user action, such as a "like" or click on an entry.
Parameters:
Name Type Description
predictionId string The ID of the prediction returned by the server for a given rank call.
entries Object | Array.<Object> An entry or array of entries to label. Each entry is an object that must define the following properties:
Properties
Name Type Description
entryId string The ID of the entry, as originally passed in the entriesToRank parameter of the rank call.
relevance number The relevance of the entry. The values must be consistent in the context of a given model. There are no restrictions on the numeric values, for instance the relevance may be binary (0/1) representing whether the user clicked on an entry or it may fall in a range (e.g., 0-100) which may have a client defined meaning.

URL(url)

Type for a URL.

This is a higher-level data type that helps PredictScript understand your data better. Use the appropriate type to make better predictions. Don't see a type you need? Let us know.
Parameters:
Name Type Description
url string String representation of the url.
Example
predict('Happy User', {url: predictscript.URL('http://predictscript.com/')})

GeoPoint(coords)

Type for a latitude-longitude point on the earth.

This is a higher-level data type that helps PredictScript understand your data better. Use the appropriate type to make better predictions. Don't see a type you need? Let us know.
Parameters:
Name Type Description
coords Object Object detailing the coordinates of the point. Properties:
  • latitude - Latitude of the point, in decimal degrees
  • longitude - Longitude of the point, in decimal degrees
Example
predict('Sunny Today', {location: predictscript.GeoPoint({latitude: 37.372, longitude: -122.081})})