モデル品質モニタリングジョブをスケジュールする - アマゾン SageMaker

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

モデル品質モニタリングジョブをスケジュールする

ベースラインを作成したら、create_monitoring_schedule()ModelQualityMonitorクラスインスタンスのメソッドを呼び出して、時間単位のモデル品質モニターをスケジュールできます。以下のセクションでは、リアルタイムエンドポイントにデプロイされたモデルとバッチ変換ジョブ用のモデル品質モニターを作成する方法を示します。

重要

監視スケジュールを作成するときに、バッチトランスフォーム入力とエンドポイント入力のどちらかを指定できますが、両方は指定できません。

データ品質監視とは異なり、モデル品質を監視する場合は Ground Truth ラベルを提供する必要があります。ただし、Ground Truth のラベルは遅れる可能性があります。これに対処するには、監視スケジュールを作成するときにオフセットを指定してください。

モデルモニターのオフセット

モデル品質のジョブには StartTimeOffsetEndTimeOffset が含まれます。これらは create_model_quality_job_definition メソッドの ModelQualityJobInput パラメータのフィールドで、次のように機能します。

  • StartTimeOffset - 指定した場合、ジョブはこの時間を開始時刻から減算します。

  • EndTimeOffset - 指定した場合、ジョブはこの時間を終了時刻から減算します。

オフセットの形式は、たとえば-PT7H で、7H は 7 時間です。-PT #H または-P #D を使用できます。ここで、H = 時間、D = 日、M = 分、# は数値です。また、オフセットはISO 8601のデュレーション形式にする必要があります

例えば、Ground Truth が 1 日後に取り込まれ始めるものの、1 週間は完全でない場合、StartTimeOffset-P8DEndTimeOffsetとに設定します-P1D。その後、ジョブを 2020-01-09T13:00 に実行するようにスケジュールした場合、2020-01-01T13:002020-01-08T13:00 間のデータが分析されます。

重要

スケジュールの繰り返し頻度は、1 つの実行が完了してから次の実行を開始するように設定する必要があります。これにより、実行の Ground Truth マージジョブとモニタリングジョブを完了できます。実行の最大ランタイムは 2 つのジョブに分割されるため、1 時間おきに実行されるモデル品質モニタリングジョブの場合、StoppingCondition の一部として指定される MaxRuntimeInSeconds は 1,800 以下にする必要があります。

リアルタイムエンドポイントにデプロイされたモデルのモデル品質監視

EndpointInputリアルタイムエンドポイントのモデル品質モニターをスケジュールするには、次のコードサンプルに示すように、endpoint_inputModelQualityMonitorインスタンスをインスタンスの引数に渡します。

from sagemaker.model_monitor import CronExpressionGenerator model_quality_model_monitor = ModelQualityMonitor( role=sagemaker.get_execution_role(), ... ) schedule = model_quality_model_monitor.create_monitoring_schedule( monitor_schedule_name=schedule_name, post_analytics_processor_script=s3_code_postprocessor_uri, output_s3_uri=s3_report_path, schedule_cron_expression=CronExpressionGenerator.hourly(), statistics=model_quality_model_monitor.baseline_statistics(), constraints=model_quality_model_monitor.suggested_constraints(), schedule_cron_expression=CronExpressionGenerator.hourly(), enable_cloudwatch_metrics=True, endpoint_input=EndpointInput( endpoint_name=endpoint_name, destination="/opt/ml/processing/input/endpoint", start_time_offset="-PT2D", end_time_offset="-PT1D", ) )

バッチ変換ジョブのモデル品質監視

BatchTransformInputバッチ変換ジョブのモデル品質モニターをスケジュールするには、次のコードサンプルに示すように、batch_transform_inputModelQualityMonitorインスタンスをインスタンスの引数に渡します。

from sagemaker.model_monitor import CronExpressionGenerator model_quality_model_monitor = ModelQualityMonitor( role=sagemaker.get_execution_role(), ... ) schedule = model_quality_model_monitor.create_monitoring_schedule( monitor_schedule_name=mon_schedule_name, batch_transform_input=BatchTransformInput( data_captured_destination_s3_uri=s3_capture_upload_path, destination="/opt/ml/processing/input", dataset_format=MonitoringDatasetFormat.csv(header=False), # the column index of the output representing the inference probablity probability_attribute="0", # the threshold to classify the inference probablity to class 0 or 1 in # binary classification problem probability_threshold_attribute=0.5, # look back 6 hour for transform job outputs. start_time_offset="-PT6H", end_time_offset="-PT0H" ), ground_truth_input=gt_s3_uri, output_s3_uri=s3_report_path, problem_type="BinaryClassification", constraints = constraints_path, schedule_cron_expression=CronExpressionGenerator.hourly(), enable_cloudwatch_metrics=True, )