翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
独自の処理コンテナを使用したスクリプトの実行
scikit-learn スクリプトを使用して、データを前処理し、モデルを評価できます。scikit-learn スクリプトを実行してこれらのタスクを実行する方法については、scikit-learn 処理ScriptProcessor クラスを使います。
次の例は、独自の処理コンテナを使用するための一般的なワークフローを示しています。ワークフローは、独自のイメージを作成し、コンテナを構築し、コンテナで Python 前処理スクリプトを実行する方法を示しています。処理ジョブは入力データを処理し、処理済みデータを Amazon Simple Storage Service (Amazon S3) に保存します。
次のサンプルを使う前に、独自の入力データとデータ処理のための Python スクリプトを準備しておく必要があります。このプロセスのエンドツーエンドのガイド付きサンプルについては、scikit-learn 処理
-
Docker ディレクトリを作成し、処理コンテナを作成するために使用される Docker ファイルを追加します。pandas をインストールし、それに scikit-learn をインストールします (同様の
RUNコマンドで独自の依存関係をインストールすることもできます)。mkdir docker %%writefile docker/Dockerfile FROM python:3.7-slim-buster RUN pip3 install pandas==0.25.3 scikit-learn==0.21.3 ENV PYTHONUNBUFFERED=TRUE ENTRYPOINT ["python3"] -
Docker コマンドを使ってコンテナを構築し、Amazon Elastic Container Registry (Amazon ECR) リポジトリを作成して、イメージを Amazon ECR にプッシュします。
import boto3 account_id = boto3.client('sts').get_caller_identity().get('Account') region = boto3.Session().region_name ecr_repository = 'sagemaker-processing-container' tag = ':latest' processing_repository_uri = '{}.dkr.ecr.{}.amazonaws.com/{}'.format(account_id, region, ecr_repository + tag) # Create ECR repository and push docker image !docker build -t $ecr_repository docker !aws ecr get-login-password --region {region} | docker login --username AWS --password-stdin {account_id}.dkr.ecr.{region}.amazonaws.com !aws ecr create-repository --repository-name $ecr_repository !docker tag {ecr_repository + tag} $processing_repository_uri !docker push $processing_repository_uri -
処理ジョブをセットアップして実行します。
image_uriを、作成したイメージの URI に置き換え、role_arnをターゲット Amazon S3 バケットにアクセスできる AWS Identity and Access Management ロールの ARN に置き換えます。preprocessing.pyを独自の Python 処理スクリプトの名前に置き換え、s3://path/to/my/input-data.csvを入力データへの Amazon S3 パスに置き換えます。from sagemaker.core.resources import ProcessingJob processing_job = ProcessingJob.create( processing_job_name="my-processing-job", role_arn='role_arn', app_specification={ "image_uri": 'image_uri', "container_entrypoint": ["python3", "/opt/ml/processing/input/code/preprocessing.py"] }, processing_resources={ "cluster_config": { "instance_count": 1, "instance_type": "ml.m5.xlarge", "volume_size_in_gb": 30 } }, processing_inputs=[ { "input_name": "code", "s3_input": { "s3_uri": 's3://path/to/preprocessing.py', "local_path": "/opt/ml/processing/input/code", "s3_data_type": "S3Prefix", "s3_input_mode": "File" } }, { "input_name": "input-data", "s3_input": { "s3_uri": 's3://path/to/my/input-data.csv', "local_path": "/opt/ml/processing/input", "s3_data_type": "S3Prefix", "s3_input_mode": "File" } } ], processing_output_config={ "outputs": [ {"output_name": "train", "s3_output": {"s3_uri": "s3://output/train", "local_path": "/opt/ml/processing/output/train", "s3_upload_mode": "EndOfJob"}}, {"output_name": "validation", "s3_output": {"s3_uri": "s3://output/validation", "local_path": "/opt/ml/processing/output/validation", "s3_upload_mode": "EndOfJob"}}, {"output_name": "test", "s3_output": {"s3_uri": "s3://output/test", "local_path": "/opt/ml/processing/output/test", "s3_upload_mode": "EndOfJob"}} ] } )
他のライブラリやシステム依存関係でも同じ手順を使用できます。既存の Docker イメージも使えます。これには、Kubernetes