Search…
⌃K
Links

Python Single Record

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 to begin logging model data to Arize
​log — Log inferences record-by-record

Install The Package

pip install arize
Arize SDK requires python >= 3.7

Initialize Arize Client

from arize.api import Client

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 = {
'state': 'ca',
'city': 'berkeley',
'merchant_name': 'Peets Coffee',
'pos_approved': True,
'item_count': 10,
'merchant_type': 'coffee shop',
'charge_amount': 20.11,
}
#example tags
tags = {
'age': 30,
'zip_code': '94610',
'device_os': 'iOS',
'server_node_id': 12,
}
​
from arize.utils.types import ModelTypes, Environments, Embedding
​
#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.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 = {
'state': 'ca',
'city': 'berkeley',
'merchant_name': 'Peets Coffee',
'pos_approved': True,
'item_count': 10,
'merchant_type': 'coffee shop',
'charge_amount': 20.11,
}
​
from arize.utils.types import ModelTypes, Environments
​
#log the features & prediction
response = arize.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.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 = {
'state': 'ca',
'city': 'berkeley',
'merchant_name': 'Peets Coffee',
'pos_approved': True,
'item_count': 10,
'merchant_type': 'coffee shop',
'charge_amount': 20.11,
}
​
from arize.utils.types import ModelTypes, Environments
​
#log the prediction, actual, and features
response = arize.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 Together

#example features
features = {
'state': 'ca',
'city': 'berkeley',
'merchant_name': 'Peets Coffee',
'pos_approved': True,
'item_count': 10,
'merchant_type': 'coffee shop',
'charge_amount': 20.11,
}
​
#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,
}
​
from arize.utils.types import ModelTypes, Environments
​
#log the prediction, actual, features, and shap
response = arize.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 [email protected] or Slack us in the #arize-support channel