Skip to main content

A helper library to interact with Arize AI APIs

Project description



Pypi CI Slack

================

Overview

A helper library to interact with Arize AI APIs


Quickstart

This guide will help you instrument your code to log model observability data. The types of data supported include prediction labels, human readable/debuggable model features and tags, actual labels (once the ground truth is learned), and other model related data. Logging model data allows you to generate powerful visualizations in the Arize platform to better understand and debug your model's behavior. Additionally, Arize can provide monitoring for the data quality, data drift, and performance of your production models.

Start logging your model data with the following steps:

1. Create your account

Sign up for a free account by reaching out to contacts@arize.com.



2. Get your service API key

When you create an account, we generate a service API key. You will need this API Key and your Organization ID for logging authentication.

3. Instrument your code

Python Client

If you are using the Arize python client, add a few lines to your code to log predictions and actuals. Logs are sent to Arize asynchronously.

Install Library

Install the Arize library in an environment using Python > 3.5.3.

$ pip3 install arize

Or clone the repo:

$ git clone https://github.com/Arize-ai/client_python.git
$ python setup.py install

Initialize Python Client

Initialize arize at the start of your sevice using your previously created API Key and Organization ID.

NOTE: We strongly suggest storing the API key as a secret or an environment variable.

from arize.api import Client

API_KEY = os.environ.get('ARIZE_API_KEY') #If passing api_key via env vars

arize = Client(organization_key='ARIZE_ORG_KEY', api_key=API_KEY)

Collect your model input features and labels you'd like to track

Real-time single prediction:

For a single real-time prediction, you can track all input features used at prediction time by logging them via a key:value dictionary.

features = {
    'state': 'ca',
    'city': 'berkeley',
    'merchant_name': 'Peets Coffee',
    'pos_approved': True,
    'item_count': 10,
    'merchant_type': 'coffee shop',
    'charge_amount': 20.11,
    }

Bulk predictions:

When dealing with bulk predictions, you can pass in input features, prediction/actual labels, and prediction_ids for more than one prediction via a Pandas Dataframe where df.columns contain feature names.

## e.g. labels from a CSV. Labels must be 2-D data frames where df.columns correspond to the label name
features_df = pd.read_csv('path/to/file.csv')

prediction_labels_df = pd.DataFrame(np.random.randint(1, 100, size=(features.shape[0], 1)))

ids_df = pd.DataFrame([str(uuid.uuid4()) for _ in range(len(prediction_labels.index))])

Log Predictions

Single real-time prediction:

## Returns an array of concurrent.futures.Future
pred = arize.log_prediction(
    model_id='sample-model-1',
    model_version='v1.23.64',
    model_type=ModelTypes.BINARY,
    prediction_id='plED4eERDCasd9797ca34',
    prediction_label=True,
    features=features,
    )

#### To confirm that the log request completed successfully, await for it to resolve:
## NB: This is a blocking call
response = pred.get()
res = response.result()
if res.status_code != 200:
  print(f'future failed with response code {res.status_code}, {res.text}')

Bulk upload of predictions:

responses = arize.log_bulk_predictions(
    model_id='sample-model-1',
    model_version='v1.23.64',
    model_type=ModelTypes.BINARY,
    prediction_ids=ids_df,
    prediction_labels=prediction_labels_df,
    features=features_df
    )
#### To confirm that the log request completed successfully, await for futures to resolve:
## NB: This is a blocking call
import concurrent.futures as cf
for response in cf.as_completed(responses):
  res = response.result()
  if res.status_code != 200:
    print(f'future failed with response code {res.status_code}, {res.text}')

The client's log_prediction/actual function returns a single concurrent future while log_bulk_predictions/actuals returns a list of concurrent futures for asynchronous behavior. To capture the logging response, you can await the resolved futures. If you desire a fire-and-forget pattern, you can disregard the responses altogether.

We automatically discover new models logged over time based on the model ID sent on each prediction.

Logging Actual Labels

NOTE: Notice the prediction_id passed in matches the original prediction sent on the previous example above.

response = arize.log_actual(
    model_id='sample-model-1',
    model_type=ModelTypes.BINARY,
    prediction_id='plED4eERDCasd9797ca34',
    actual_label=False
    )

Bulk upload of actuals:

responses = arize.log_bulk_actuals(
    model_id='sample-model-1',
    model_type=ModelTypes.BINARY,
    prediction_ids=ids_df,
    actual_labels=actual_labels_df,
    )

#### To confirm that the log request completed successfully, await for futures to resolve:
## NB: This is a blocking call
import concurrent.futures as cf
for response in cf.as_completed(responses):
  res = response.result()
  if res.status_code != 200:
    print(f'future failed with response code {res.status_code}, {res.text}')

Once the actual labels (ground truth) for your predictions have been determined, you can send them to Arize and evaluate your metrics over time. The prediction id for one prediction links to its corresponding actual label so it's important to note those must be the same when matching events.

4. Log In for Analytics

That's it! Once your service is deployed and predictions are logged you'll be able to log into your Arize account and dive into your data, slicing it by features, tags, models, time, etc.

Analytics Dashboard




Logging SHAP values

Log SHAP feature importances to the Arize platform to explain your model's predictions. By logging SHAP values you gain the ability to view the global feature importances of your predictions as well as the ability to perform cohort and prediction based analysis to compare feature importance values under varying conditions. For more information on SHAP and how to use SHAP with Arize, check out our SHAP documentation.


Other languages

If you are using a different language, you'll be able to post an HTTP request to our Arize edge-servers to log your events.

HTTP post request to Arize

curl -X POST -H "Authorization: YOU_API_KEY" "https://log.arize.com/v1/log" -d'{"organization_key": "YOUR_ORG_KEY", "model_id": "test_model_1", "prediction_id":"test100", "prediction":{"model_version": "v1.23.64", "features":{"state":{"string": "CO"}, "item_count":{"int": 10}, "charge_amt":{"float": 12.34}, "physical_card":{"string": true}}, "prediction_label": {"binary": false}}}'

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

arize-2.1.0.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

arize-2.1.0-py2.py3-none-any.whl (25.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file arize-2.1.0.tar.gz.

File metadata

  • Download URL: arize-2.1.0.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.3

File hashes

Hashes for arize-2.1.0.tar.gz
Algorithm Hash digest
SHA256 beff55ea3598251faf7ba982534500374bd4c89ec06951e5fcc6d88c5830d19d
MD5 a6551c8f571d290a0a7c93fd18648f4b
BLAKE2b-256 ff5a012640657b6c29a14a764bea0fa8338979d504215a5d1b33b2f56a9e73ea

See more details on using hashes here.

File details

Details for the file arize-2.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: arize-2.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 25.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.3

File hashes

Hashes for arize-2.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 7476c1d14620358c2c00d59c97463f3106e9de9362a46448acd6e74e50678822
MD5 eb60032e7b11cccc8a5e96617408d50b
BLAKE2b-256 62462dcc6ad19b6825875e6e2d435fea06a0f6d3e359611ec74f1636db7bd582

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page