重要
この記事では、Azure Machine Learning SDK v1 の使用に関する情報を提供します。 SDK v1 は、2025 年 3 月 31 日の時点で非推奨です。 サポートは 2026 年 6 月 30 日に終了します。 SDK v1 は、その日付までインストールして使用できます。
2026 年 6 月 30 日より前に SDK v2 に移行することをお勧めします。 SDK v2 の詳細については、「 Azure Machine Learning CLI と Python SDK v2 とは」 および SDK v2 リファレンスを参照してください。
この記事では、デザイナー パイプラインにコードを追加してログ メトリックを有効にする方法について説明します。 また、Azure Machine Learning スタジオの Web ポータルを使用してこれらのログを表示する方法についても説明します。
SDK 作成エクスペリエンスを使用したメトリックのログ記録の詳細については、「 ログとビューのメトリックとログ ファイル」を参照してください。
Execute Python Script を使用してログ記録を有効にする
Execute Python Script コンポーネントを使用して、デザイナー パイプラインでログ記録を有効にします。 このワークフローを使用して任意の値をログに記録することができますが、Evaluate Model コンポーネントからメトリックをログに記録し、複数の実行にわたってモデルのパフォーマンスを追跡する場合に特に便利です。
次の例は、Evaluate Model コンポーネントと Execute Python Script コンポーネントを使用して、トレーニング済みの 2 つのモデルの平均二乗誤差をログに記録する方法を示しています。
Execute Python Script コンポーネントを Evaluate Model コンポーネントの出力に接続します。
Execute Python Script のコード エディターに次のコードを貼り付けて、トレーニングされたモデルの平均絶対誤差をログに記録します。 同様のパターンを使用して、デザイナーで他の値をログに記録できます。
適用対象:
Azure Machine Learning SDK v1 for Python
# dataframe1 contains the values from Evaluate Model def azureml_main(dataframe1=None, dataframe2=None): print(f'Input pandas.DataFrame #1: {dataframe1}') from azureml.core import Run run = Run.get_context() # Log the mean absolute error to the parent run to see the metric in the run details page. # Note: 'run.parent.log()' should not be called multiple times because of performance issues. # If repeated calls are necessary, cache 'run.parent' as a local variable and call 'log()' on that variable. parent_run = Run.get_context().parent # Log left output port result of Evaluate Model. This also works when evaluate only 1 model. parent_run.log(name='Mean_Absolute_Error (left port)', value=dataframe1['Mean_Absolute_Error'][0]) # Log right output port result of Evaluate Model. The following line should be deleted if you only connect one Score component to the` left port of Evaluate Model component. parent_run.log(name='Mean_Absolute_Error (right port)', value=dataframe1['Mean_Absolute_Error'][1]) return dataframe1,
このコードでは、Azure Machine Learning Python SDK を使用して値をログに記録します。 Run.get_context()
を使用して、現在の実行のコンテキストを取得します。 その後、 run.parent.log()
メソッドを使用して、そのコンテキストに値を記録します。 parent
を使用して、コンポーネントの実行ではなく、親パイプラインの実行に値を記録します。
Python SDK を使用して値をログに記録する方法の詳細については、「 ログとメトリックとログ ファイルの表示」を参照してください。
ログを表示する
パイプラインの実行が完了すると、実験ページに Mean_Absolute_Error が表示されます。