Arize AI
Search…
Python Batch
1. Install, Import, and Instantiate Arize
!pip install arize
import pandas as pd
from arize.pandas.logger import Client, Schema
from arize.utils.types import Environments, ModelTypes
API_KEY = 'ARIZE_API_KEY'
SPACE_KEY = 'YOUR SPACE KEY'
arize_pandas_client = Client(space_key=SPACE_KEY, api_key=API_KEY)
2. Import your data as a dataframe
# Example import from a CSV
prod_df = pd.read_csv("YOUR_DATA.csv")
3. Capture your dataframe's feature, prediction, and actual column names
# example feature columns from sample dataframe, swap these out to reflect your own data!
feature_column_names = [
"YOUR_FEATURE_COL_NAME_1",
"YOUR_FEATURE_COL_NAME_2",
"YOUR_FEATURE_COL_NAME_3"
]
prediction_label_column_name="YOUR_PREDICTION_LABEL_COLUMN_NAME"
prediction_score_column_name="YOUR_PREDICTION_SCORE_COLUMN_NAME"
actual_label_column_name="YOUR_ACTUAL_LABEL_COLUMN_NAME"
actual_score_column_name="YOUR_ACTUAL_SCORE_COLUMN_NAME"
4. Log the dataframe to Arize
# Log the prediction using arize_pandas_client.log
# Be sure to set up your own model parameters in the method call below
schema = Schema(
prediction_id_column_name="YOUR_PREDICTION_ID_COLUMN_NAME",
timestamp_column_name="YOUR_PREDICTION_TS_COLUMN_NAME", # optional timestamp column
prediction_label_column_name=prediction_label_column_name,
actual_label_column_name=actual_label_column_name,
prediction_score_column_name=prediction_score_column_name,
actual_score_column_name=actual_score_column_name,
feature_column_names=feature_column_names
)
res = arize_pandas_client.log(
dataframe=prod_df,
model_id='YOUR_MODEL_NAME',
model_version='v1',
model_type=ModelTypes.SCORE_CATEGORICAL, # or ModelTypes.NUMERIC, see docs.arize.com for more info
environment=Environments.PRODUCTION, # see docs.arize.com for more info
schema=schema,
)
5. Inspect the response
if res.status_code == 200:
print(f"✅ You have successfully logged production set to Arize")
else:
print(f"logging failed with response code {res.status_code}, {res.text}")
Copy link