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
Example 1: Logging Features, Tags, and Predictions Only
# Example features; features & tags can be optionally defined with typingfeatures ={'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 tagstags ={'age':30,'zip_code':'94610','device_os':'iOS','server_node_id':12,}# example embeddingsembedding_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 predictionresponse = 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 deliveryres = 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 typingfeatures ={'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 & predictionresponse = 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 actualactual_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 deliveryres = 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 typingfeatures ={'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 featuresresponse = 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 deliveryres = 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 & tags can be optionally defined with typingfeatures ={'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 shapresponse = 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 deliveryres = 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}')