log

Call arize.log to publish the features, predicted label, actual observed label, and SHAP for a single data point to Arize for monitoring, analysis, and explainability.

Use the initialized Arize client to call arize.log() with a predicted label, predicted actual, their feature inputs, their shap values, and a corresponding prediction id. Once records are sent to Arize's platform, you'll be able to visualize and analyze data holistically or within aggregated slices.

arize.log() returns a Response. You can await on the Response to complete to ensure successful delivery of records.

When logging a prediction for the first time for a new model, we classify the model in the Arize platform based on the data type of the prediction.

For more information on model schema discovery, visit here:

pageWhat Is A Model Schema

API

<T> Response log(
   final String modelId,
   final String modelVersion, 
   final String predictionId,
   final Map<String, ?> features,
   final Map<String, ?> tags,
   final Map<String, Embedding> embeddingFeatures,
   final T predictionLabel,
   final T actualLabel,
   final Map<String, Double> shapValues,
   long predictionTimestamp) throws IllegalArgumentExceptionArgument, IOException

API Arguments

Argument

Type(s)

Description

Required

modelId

String

Costumer provided unique identifier for a given model.

Y

modelVersion

String

Used to group together a subset of predictions and actuals for a given model_id. If null is passes, a prediction will only be associated with a model id with no version.

Y

predictionId

String

Unique string identifier for specific label. Must match a previously sent Prediction record.

Y

features

Map<String, ?>

Where value can be oneOf: String, int, long, short, double, float, boolean, List<String>

Map containing human readable and debuggable model features. Map keys must be String and values one of: String, int, long, short, double, float, boolean, List<String>

Optional

embeddingFeatures

Map<String, Embedding>

Map containing human readable and debuggable model embedding features. Map keys must be String and values Embedding

tags

Map<String, ?> Where value can be oneOf: String, int, long, short, double, float, boolean, List<String>

Map containing human readable and debuggable model features. Map keys must be String and values one of: String, int, long, short, double, float, boolean, List<String>

Optional

predictionLabel

String, boolean, int, long, short, float, double

The predicted label for a given model input (associated via predictionId).

Optional

actualLabel

String, boolean, int, long, short, float, double

The actual label for a given model input (associated via predictionId)

Optional

shapValues

Map<String, Double>

Map keys must be String and match the names of the features used in the prediction; values must be Double.

Optional

predictionTimestamp

long

If long representing Unix epoch time in seconds, set overwrite the timestamp for prediction.

If null, default to current timestamp.

Important: Future and Historical predictions are supported up to 1 year from current wall clock time.

Optional

Sample Code (Categorical)

import com.arize.ArizeClient;
import com.arize.Response;
import com.arize.types.Embedding;

Map<String, String> features = new HashMap<>();
features.put("key", "value");

Map<String, Embedding> embeddingFeatures = new HashMap<>();
embeddingFeatures.put(
    "embedding_feature_key",
    new Embedding(
        Arrays.asList(1.0, 0.5),
        Arrays.asList("test", "token", "array"),
        "https://example.com/image.jpg"));
        
Map<String, String> tags = new HashMap<>();
tags.put("tag_key", "tag_value");

ArizeClient arize = new ArizeClient(System.getenv("ARIZE_API_KEY"), System.getenv("ARIZE_SPACE_KEY"));

Response asyncResponse = arize.log("exampleModelId", "v1", UUID.randomUUID().toString(), features, embeddingFeatures, tags, "pear", null, null, 0);

// This is a blocking call similar to future.get()
asyncResponse.resolve();

// Check that the API call was successful
switch (asyncResponse.getResponseCode()) {
    case OK:
        // TODO: Success!
        System.out.println("Success!!!");
        break;
    case AUTHENTICATION_ERROR:
        // TODO: Check to make sure your Arize API KEY and Space key are correct
        break;
    case BAD_REQUEST:
        // TODO: Malformed request
        System.out.println("Failure Reason: " + asyncResponse.getResponseBody());
    case NOT_FOUND:
        // TODO: API endpoint not found, client is likely malconfigured, make sure you
        // are not overwriting Arize's endpoint URI
        break;
    case UNEXPECTED_FAILURE:
        // TODO: Unexpected failure, check for a reason on response body
        System.out.println("Failure Reason: " + asyncResponse.getResponseBody());
        break;
}

// Don't forget to shutdown the client with your application shutdown hook.
arize.close();

Sample Code - Score Categorical

import com.arize.ArizeClient;
import com.arize.Response;
import com.arize.types.Embedding;

Map<String, String> features = new HashMap<>();
features.put("key", "value");

Map<String, Embedding> embeddingFeatures = new HashMap<>();
embeddingFeatures.put(
    "embedding_feature_key",
    new Embedding(
        Arrays.asList(1.0, 0.5),
        Arrays.asList("test", "token", "array"),
        "https://example.com/image.jpg"));
        
Map<String, String> tags = new HashMap<>();
tags.put("tag_key", "tag_value");

ArizeClient arize = new ArizeClient(System.getenv("ARIZE_API_KEY"), System.getenv("ARIZE_SPACE_KEY"));

// Score Categorical Label
ArizeClient.ScoredCategorical scoreLabel = new ArizeClient.ScoredCategorical("Categorical Label", 20.21);
Response asyncResponse = client.log("modelId", "modelVersion", "predictionId", features, embeddingFeatures, tags, scoreLabel, null, null, 0);

// This is a blocking call similar to future.get()
asyncResponse.resolve();

// Check that the API call was successful
switch (asyncResponse.getResponseCode()) {
    case OK:
        // TODO: Success!
        System.out.println("Success!!!");
        break;
    case AUTHENTICATION_ERROR:
        // TODO: Check to make sure your Arize API KEY and Space key are correct
        break;
    case BAD_REQUEST:
        // TODO: Malformed request
        System.out.println("Failure Reason: " + asyncResponse.getResponseBody());
    case NOT_FOUND:
        // TODO: API endpoint not found, client is likely malconfigured, make sure you
        // are not overwriting Arize's endpoint URI
        break;
    case UNEXPECTED_FAILURE:
        // TODO: Unexpected failure, check for a reason on response body
        System.out.println("Failure Reason: " + asyncResponse.getResponseBody());
        break;
}

// Don't forget to shutdown the client with your application shutdown hook.
arize.close();

Sample Code - Sending in Numeric Sequences for Ranking Models

The following code snippet highlights the use of the ScoredCategorical constructor for including a numeric sequence in the actualScoreLabel

import com.arize.ArizeClient.ScoredCategorical;

Map<String, String> features = new HashMap<>();
features.put("key", "value");

// Score Categorical Label
ScoredCategorical predictionScoreLabel = new ScoredCategorical("Categorical Label", 20.21);
ScoredCategorical actualScoreLabel = new ScoredCategorical("relevant", 4.13, Arrays.asList(0.12, 0.23, 0.34))

Response response = client.log("modelId", "modelVersion", "predictionId", features, predictionScoreLabel, actualScoreLabel, null, 0);

// This is a blocking call similar to future.get()
asyncResponse.resolve();

Questions? Email us at support@arize.com or Slack us in the #arize-support channel

Last updated

Copyright © 2023 Arize AI, Inc