This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import argparse | |
| import os | |
| import warnings | |
| import pandas as pd | |
| import numpy as np | |
| from sklearn.model_selection import train_test_split | |
| from sklearn.exceptions import DataConversionWarning | |
| warnings.filterwarnings(action='ignore', category=DataConversionWarning) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| set -eux | |
| echo "Writing to Dockerfile" | |
| cat <<EOF > Dockerfile | |
| FROM python:3.7-slim-buster | |
| RUN pip3 install pandas==0.25.3 scikit-learn==0.21.3 | |
| ENV PYTHONUNBUFFERED=TRUE | |
| ENTRYPOINT ["python3"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## We poll for the processing Job at intervals | |
| get_processing_job_status = LambdaStep( | |
| state_id="GetDataProcessingJob", | |
| parameters={ | |
| "FunctionName": "arn:aws:lambda:eu-west-1:1234567890:function:GetProcessingJobStatus", #replace with the name of the function you created | |
| "Payload": { | |
| "JobName": create_processing_job_step.output()['Payload']['JobName'] | |
| } | |
| } | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## We poll for the processing Job at intervals | |
| get_processing_job_status = LambdaStep( | |
| state_id="GetDataProcessingJob", | |
| parameters={ | |
| "FunctionName": "arn:aws:lambda:eu-west-1:961618251897:function:GetProcessingJobStatus", #replace with the name of the function you created | |
| "Payload": { | |
| "JobName": create_processing_job_step.output()['Payload']['JobName'] | |
| } | |
| } | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data_processing_configuration = dict( | |
| JobName=execution_input['JobName'], | |
| IAMRole=execution_input['IAMRole'], | |
| LocalStorageSizeGB=50, | |
| S3CodePath=execution_input['S3CodePath'], | |
| S3InputDataPath=execution_input['S3InputDataPath'], | |
| S3OutputDataPath=execution_input['S3OutputDataPath'], | |
| EcrContainerUri=execution_input['EcrContainerUri'] | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import boto3 | |
| import json | |
| sm_client = boto3.client('sagemaker') | |
| def lambda_handler(event, context): | |
| """ | |
| :param event: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sm_client = boto3.client('sagemaker') | |
| from sagemaker.processing import ScriptProcessor, ProcessingInput, ProcessingOutput | |
| BASE_PROCESSING_IMAGE = '' | |
| INPUT_DATA_DESTINATION = '/opt/ml/processing/input_data' | |
| PROCESSED_DATA_PATH = '/opt/ml/processing/processed_data' | |
| DEFAULT_VOLUME_SIZE = 100 | |
| DEFAULT_INSTANCE_TYPE = 'ml.m5.xlarge' | |
| DEFAULT_INSTANCE_COUNT = 1 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| workflow_definition = Chain([ | |
| data_processing_step, | |
| training_step, | |
| model_step, | |
| transform_step | |
| ]) | |
| workflow = Workflow( | |
| name='MyTrainTransformDeployWithGlue_v2', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| xgb = sagemaker.estimator.Estimator( | |
| get_image_uri(region, 'xgboost'), | |
| sagemaker_execution_role, | |
| train_instance_count = 1, | |
| train_instance_type = 'ml.m4.4xlarge', | |
| train_volume_size = 5, | |
| output_path = f's3://{model_bucket}/{prefix}', | |
| sagemaker_session = session | |
| ) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data_processing_step = GlueStartJobRunStep( | |
| state_id='GlueDataProcessingStep', | |
| parameters={ | |
| 'JobName': glue_job_name, | |
| 'Arguments': { | |
| '--s3_input_data_path': execution_input['S3InputDataPath'], | |
| '--s3_processed_data_path': execution_input['S3OutputDataPath']# | |
| } | |
| } | |
| ) |
NewerOlder