与Arize AI api交互的助手库
arize的Python项目详细描述
==============
概述
与Arize AI api交互的助手库
快速启动
一旦了解了基本的真相,就可以让模型记录预测标签、人类可读/调试的特性和标记,以及实际的标签事件。记录的事件允许Arize平台生成特性/标记、标签和其他模型元数据的可视化。此外,该平台将为您的生产模型提供数据质量监控和数据分发警报。在
按照以下步骤开始日志记录。在
1。创建您的帐户
联系contacts@arize.com注册一个免费帐户。在
2。获取服务密钥
当您创建帐户时,我们将生成一个服务api密钥。您将需要此API密钥和组织id来进行日志验证。在
3。插入代码
Python客户端
如果您使用的是python客户机,请在代码中添加几行记录预测和实际值。日志被异步发送到Arize。在
安装库
在使用Python>;3.5.3的环境中安装我们的库。在
$ pip3 install arize
或克隆回购:
^{pr2}$初始化Python客户端
在服务开始时使用先前创建的组织ID和API密钥初始化arize
NOTE: We suggest adding the API KEY as secrets or an environment variable.
fromarize.apiimportClientAPI_KEY=os.environ.get('ARIZE_API_KEY')#If passing api_key via env varsarize=Client(organization_key='ARIZE_ORG_KEY',api_key=API_KEY)
收集要跟踪的模型输入功能和标签
实时单次预测:
对于实时的单个预测过程,您可以通过键:值字典。在
features={'state':'ca','city':'berkeley','merchant_name':'Peets Coffee','pos_approved':True,'item_count':10,'merchant_type':'coffee shop','charge_amount':20.11,}
批量预测:
在处理批量预测时,可以通过Pandas数据帧传入输入特性、预测/实际标签和预测_id,其中数据框列包含要素名称。在
## e.g. labels from a CSV. Labels must be 2-D data frames where df.columns correspond to the label namefeatures_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_inrange(len(prediction_labels.index))])
日志预测
单次实时精度:
## Returns an array of concurrent.futures.Futurepred=arize.log_prediction(model_id='sample-model-1',model_version='v1.23.64',## Optionalprediction_id='plED4eERDCasd9797ca34',prediction_label=True,features=features,)#### To confirm request future completed successfully, await for it to resolve:## NB: This is a blocking callresponse=pred.get()res=response.result()ifres.status_code!=200:print(f'future failed with response code {res.status_code}, {res.text}')
批量上传预测:
responses=arize.log_bulk_predictions(model_id='sample-model-1',model_version='v1.23.64',## Optionalprediction_ids=ids_df,prediction_labels=prediction_labels_df,features=features_df)#### To confirm request futures completed successfully, await for futures to resolve:## NB: This is a blocking callimportconcurrent.futuresascfforresponseincf.as_completed(responses):res=response.result()ifres.status_code!=200:print(f'future failed with response code {res.status_code}, {res.text}')
Arize log_predition/actual返回单个并发未来,而log_bulk_predictions/actuals返回异步行为的并发未来列表。要捕获日志响应,可以等待已解决的未来。如果你想要一个火而忘记了模式,你可以完全打乱回应。在
我们会根据每个预测发送的模型ID自动发现随时间而记录的新模型。在
记录实际标签
NOTE: Notice the prediction_id passed in matched the original prediction send on the previous example above.
response=arize.log_actual(model_id='sample-model-1',prediction_id='plED4eERDCasd9797ca34',actual_label=False)
实际值的批量上载:
responses=arize.log_bulk_actuals(model_id='sample-model-1',prediction_ids=ids_df,actual_labels=actual_labels_df,)#### To confirm request futures completed successfully, await for futures to resolve:## NB: This is a blocking callimportconcurrent.futuresascfforresponseincf.as_completed(responses):res=response.result()ifres.status_code!=200:print(f'future failed with response code {res.status_code}, {res.text}')
一旦确定了预测的实际标签(基本事实),您就可以将这些标签发送给Arize,并随时间评估您的度量。一个预测的预测id链接到它对应的实际标签,所以在匹配事件时注意这些必须是相同的。在
4。登录分析
就这样!一旦你的服务被部署和预测被记录,你将能够登录到你的阿里兹帐户和深入你的数据。按功能、标签、模型、时间等对其进行切片
分析仪表板
其他语言
如果您使用不同的语言,您可以向我们的Arize边缘服务器发布一个HTTP请求来记录您的事件。在
对Arize的HTTP post请求
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}}}'
- 项目
标签: