Single Record Logging

Stream Logging API- Designed for record by record sending of data to Arize

This API is designed for record-by-record data ingestion. It is not designed for a large set of data. Check out the arize.pandas for a faster experience for batch logging.

The most commonly used functions/objects are:

Client — Initialize to begin logging model data to Arize

log — Log inferences record-by-record

Install the Package

pip install arize

Initialize Arize Client

Initialize Arize Clientto begin logging model inferences.

from arize.api import Client

# create Arize client
SPACE_KEY = "YOUR_SPACE_KEY" 
API_KEY = "YOUR_API_KEY" 

arize_client = Client(space_key=SPACE_KEY, api_key=API_KEY) 

Single Record Examples

For examples and interactive notebooks, see https://docs.arize.com/arize/examples

Example 1: Logging Features, Tags, and Predictions Only

# Example features; features & tags can be optionally defined with typing
features = {
    'state': 'ca',
    'city': 'berkeley',
    'merchant_name': 'Peets Coffee',
    'pos_approved': TypedValue(value=False, type=ArizeTypes.INT),
    'item_count': 10,
    'merchant_type': 'coffee shop',
    'charge_amount': TypedValue(value=20.11, type=ArizeTypes.FLOAT),
}
    
# example tags
tags = {
    'age': 30,
    'zip_code': '94610',
    'device_os': 'iOS',
    'server_node_id': 12,
}

# example embeddings
embedding_features = {
        'image_embedding': Embedding(
            vector=np.array([1.0, 2, 3]),
            link_to_data='https://my-bucket.s3.us-west-2.amazonaws.com/puppy.png',
        ),
        'nlp_embedding_sentence': Embedding(
            vector=pd.Series([4.0, 5.0, 6.0, 7.0]),
            data='This is a test sentence',
        ),
        'nlp_embedding_tokens': Embedding(
            vector=pd.Series([4.0, 5.0, 6.0, 7.0]),
            data=['This', 'is', 'a', 'sample', 'token', 'array'],
        ),
    }

# log the prediction
response = arize_client.log(
    prediction_id='plED4eERDCasd9797ca34',
    model_id='sample-model-1',
    model_type=ModelTypes.SCORE_CATEGORICAL,
    environment=Environments.PRODUCTION,
    model_version='v1',
    prediction_timestamp=1618590882,
    prediction_label=('Fraud',.4)
    features=features,
    embedding_features=embedding_features
    tags=tags
)

# Listen to response code to ensure successful delivery
res = response.result()
if res.status_code == 200:
    print('Success sending Prediction!')
else:
    print(f'Log failed with response code {res.status_code}, {res.text}')

Example 2: Logging Features & Predictions First, Then Delayed Actuals

# Example features; features & tags can be optionally defined with typing
features = {
    'state': 'ca',
    'city': 'berkeley',
    'merchant_name': 'Peets Coffee',
    'pos_approved': TypedValue(value=False, type=ArizeTypes.INT),
    'item_count': 10,
    'merchant_type': 'coffee shop',
    'charge_amount': TypedValue(value=20.11, type=ArizeTypes.FLOAT),
}

# log the features & prediction
response = arize_client.log(
    prediction_id='plED4eERDCasd9797ca34',
    model_id='sample-model-1',
    model_type=ModelTypes.SCORE_CATEGORICAL,
    environment=Environments.PRODUCTION,
    model_version='v1',
    prediction_timestamp=1618590882,
    features=features,
    prediction_label=('Fraud',.4),
    tags=tags
)

res = response.result()
if res.status_code == 200:
    print('Success sending Prediction!')
else:
    print(f'Log failed with response code {res.status_code}, {res.text}')

# log the actual
actual_response = arize_client.log(
    prediction_id='plED4eERDCasd9797ca34',
    model_id='sample-model-1',
    model_type=ModelTypes.SCORE_CATEGORICAL,
    environment=Environments.PRODUCTION,
    actual_label=('Fraud',1),
    tags=tags)

# Listen to response code to ensure successful delivery
res = actual_response.result()
if res.status_code == 200:
    print('Success sending Actual!')
else:
    print(f'Log failed with response code {res.status_code}, {res.text}')

Example 3: Logging Features, Predictions and Actuals Together

# Example features; features & tags can be optionally defined with typing
features = {
    'state': 'ca',
    'city': 'berkeley',
    'merchant_name': 'Peets Coffee',
    'pos_approved': TypedValue(value=False, type=ArizeTypes.INT),
    'item_count': 10,
    'merchant_type': 'coffee shop',
    'charge_amount': TypedValue(value=20.11, type=ArizeTypes.FLOAT),
}

# log the prediction, actual, and features
response = arize_client.log(
    prediction_id='plED4eERDCasd9797ca34',
    model_id='sample-model-1',
    model_type=ModelTypes.SCORE_CATEGORICAL,
    environment=Environments.PRODUCTION,
    model_version='v1',
    prediction_timestamp=1618590882,
    features=features,
    prediction_label=('False', .4),
    actual_label=('True', 1),
    tags=tags
)

# Listen to response code to ensure successful delivery
res = response.result()
if res.status_code == 200:
    print('Success sending Prediction and Actual!')
else:
    print(f'Log failed with response code {res.status_code}, {res.text}')

Example 4: Logging Predictions, Actuals, and SHAP Togethe

# Example features; features & tags can be optionally defined with typing
features = {
    'state': 'ca',
    'city': 'berkeley',
    'merchant_name': 'Peets Coffee',
    'pos_approved': TypedValue(value=False, type=ArizeTypes.INT),
    'item_count': 10,
    'merchant_type': 'coffee shop',
    'charge_amount': TypedValue(value=20.11, type=ArizeTypes.FLOAT),
}

# example SHAP values 
shaps = {
    'state': 0.23,
    'city': 0.31,
    'merchant_name': 0.10,
    'pos_approved': 0.02,
    'item_count': 0.06,
    'merchant_type': 0.11,
    'charge_amount': 0.29,
}

# log the prediction, actual, features, and shap
response = arize_client.log(
    prediction_id='plED4eERDCasd9797ca34',
    model_id='sample-model-1',
    model_type=ModelTypes.SCORE_CATEGORICAL,
    environment=Environments.PRODUCTION,
    model_version='v1',
    prediction_timestamp=1618590882,
    features=features,
    prediction_label=('False', .4),
    actual_label=('True',1),
    tags=tags,
    shap_values=shaps)
    
# Listen to response code to ensure successful delivery
res = response.result()
if res.status_code == 200:
    print('Success sending Prediction, Actual, and SHAPs!')
else:
    print(f'Log failed with response code {res.status_code}, {res.text}')

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

Last updated

Copyright © 2023 Arize AI, Inc