本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
解析结果
在运行基线处理作业并获得数据集的统计数据和约束条件后,您可以执行监控作业来计算统计数据并列出遇到的与基线约束相关的任何违规行为。默认情况下,您的账户中也会报告亚马逊 CloudWatch 指标。有关在亚马逊 SageMaker Studio 中查看监控结果的信息,请参阅在亚马逊 SageMaker 工作室中可视化实时终端节点的结果。
列出执行
该计划以指定的间隔开始监控作业。以下代码列出了最新的五次执行。如果您在创建小时计划后运行此代码,则执行可能为空,并且您可能必须等到跨越小时边界 (UTC) 才能看到执行开始。下面的代码包含等待的逻辑。
mon_executions = my_default_monitor.list_executions() print("We created a hourly schedule above and it will kick off executions ON the hour (plus 0 - 20 min buffer.\nWe will have to wait till we hit the hour...") while len(mon_executions) == 0: print("Waiting for the 1st execution to happen...") time.sleep(60) mon_executions = my_default_monitor.list_executions()
检查特定的执行情况
在上一步中,您选择了最新已完成或失败的计划执行结果。您可以探索探索什么是正确的,什么是错误的。终端状态包括:
-
Completed
— 监控执行已完成,在违规报告中未发现任何问题。 -
CompletedWithViolations
— 执行已完成,但检测到违反约束条件。 -
Failed
— 监视执行失败,可能是由于客户端错误(例如,角色问题)或基础架构问题造成的。要确定原因,请参阅FailureReason
和ExitMessage
。
latest_execution = mon_executions[-1] # latest execution's index is -1, previous is -2 and so on.. time.sleep(60) latest_execution.wait(logs=False) print("Latest execution status: {}".format(latest_execution.describe()['ProcessingJobStatus'])) print("Latest execution result: {}".format(latest_execution.describe()['ExitMessage'])) latest_job = latest_execution.describe() if (latest_job['ProcessingJobStatus'] != 'Completed'): print("====STOP==== \n No completed executions to inspect further. Please wait till an execution completes or investigate previously reported failures.")
report_uri=latest_execution.output.destination print('Report Uri: {}'.format(report_uri))
列出生成的报告
列出生成的报告使用以下代码列出生成的报告。
from urllib.parse import urlparse s3uri = urlparse(report_uri) report_bucket = s3uri.netloc report_key = s3uri.path.lstrip('/') print('Report bucket: {}'.format(report_bucket)) print('Report key: {}'.format(report_key)) s3_client = boto3.Session().client('s3') result = s3_client.list_objects(Bucket=report_bucket, Prefix=report_key) report_files = [report_file.get("Key") for report_file in result.get('Contents')] print("Found Report Files:") print("\n ".join(report_files))
违规报告
如果存在与基线比较的违规情况,则会在违规报告中生成。使用以下代码列出违规行为。
violations = my_default_monitor.latest_monitoring_constraint_violations() pd.set_option('display.max_colwidth', -1) constraints_df = pd.io.json.json_normalize(violations.body_dict["violations"]) constraints_df.head(10)
这仅适用于包含表格式数据的数据集。以下架构文件指定计算的统计数据和监视的违规情况。
表格数据集的输出文件 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
文件名称 | 描述 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
statistics.json |
包含所分析数据集中每个特征的列式统计数据。请参阅下一个主题中此文件的架构。 注意创建此文件仅用于数据质量监控。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
constraint_violations.json |
包含在当前数据集中找到的相对于 |
默认情况下,亚马逊 SageMaker 模型监控器预建容器会为每项功能保存一组亚马逊 CloudWatch指标。
容器代码可以在这个位置发出 CloudWatch 指标:/opt/ml/output/metrics/cloudwatch
.