繁体   English   中英

SageMaker 模型中的自定义特征工程

[英]Custom Feature Engineering in SageMaker Model

我在 SageMaker 中使用批量转换来调用存储的 XGBoost 模型并根据存储在 S3 中的数据对其进行评分。 但是,在调用模型之前,我必须对列进行多次转换。

以下是用于批量转换的代码:

batch_input = 's3://{}/{}/batch/test_data_Batch.csv'.format(bucket,prefix) # test data used for prediction
batch_output = 's3://{}/{}/batch/batch-inference/test_data_Batch.csv.out'.format(bucket,prefix)
Modelname = '<your_model_name_here>' # the model name we already have
transformJobName = 'DEMO-xgboost-churn-call-batch'+ strftime("%Y-%m-%d-%H-%M-%S", gmtime())

client = boto3.client('sagemaker')

create_batch = client.create_transform_job(
    TransformJobName=transformJobName,
    ModelName=Modelname,
    MaxConcurrentTransforms=0,
    MaxPayloadInMB=6,
    BatchStrategy='MultiRecord',
    TransformInput={
        'DataSource': {
            'S3DataSource': {
                'S3DataType': 'S3Prefix',
                'S3Uri': batch_input 
            }
        },
        'ContentType': 'text/csv',
        'CompressionType': 'None',
        'SplitType': 'Line'
    },
    TransformOutput={
        'S3OutputPath': batch_output,
        'AssembleWith': 'Line'
    },
    TransformResources={
        'InstanceType': 'ml.m4.xlarge',
        'InstanceCount': 1
    }
    )

在使用 XGBoost 模型运行批量转换之前,如何调用特征工程 Python 函数来转换数据? 一些指针会有所帮助。 谢谢你。

为迟到的回复道歉。

我相信您可以采用几种方法在 SageMaker 中结合 Batch 进行一些预处理。

我假设您使用的是 SageMaker 提供的 XGBoost 图像: https : //github.com/aws/sagemaker-xgboost-container

  1. 如果您使用的是开源 SageMaker XGBoost 容器,那么您可以修改您的模型图像脚本来处理您的预处理和后处理。 这将要求您扩展或构建 XGBoost 映像并将其作为 ECR 映像托管在您的 AWS 账户中。

有关扩展框架图像的示例,请参阅: https : //docs.aws.amazon.com/sagemaker/latest/dg/prebuilt-containers-extend.html

扩展图像后,您可能希望修改您的用户脚本来处理您的预处理。

XGBoost 容器中的用户脚本示例: https : //github.com/aws/sagemaker-xgboost-container/blob/master/test/resources/boston/single_machine_customer_script.py

这可能需要一些时间,我建议使用 Python SDK 和本地模式来加快迭代速度: https : //github.com/aws-samples/amazon-sagemaker-local-mode

  1. 在使用 SageMaker 批处理之前,利用 SageMaker 推理管道拥有一个单独的图像来处理数据预处理。

与上面的方法类似,但是在这种情况下,我们将生成一个单独的 Image 来单独处理我们的数据,然后将该数据传递给我们的原始模型。

根据您的方法,这可能需要扩展现有容器或创建一个完全具有所需依赖项的新容器。

https://docs.aws.amazon.com/sagemaker/latest/dg/inference-pipeline-batch.html

  1. 还有 SageMaker 处理

https://aws.amazon.com/blogs/aws/amazon-sagemaker-processing-fully-managed-data-processing-and-model-evaluation/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM