如何解决SageMaker模型中的自定义特征工程
我正在SageMaker中使用Batch Transform调用存储的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。
- 如果您使用的是开源 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。
- 在使用 SageMaker 批处理之前,利用 SageMaker 推理管道拥有一个单独的图像来处理数据预处理。
类似于上面的方法,但是在这种情况下,我们将生成一个单独的图像来单独处理我们的数据,然后将该数据传递给我们的原始模型。
根据您的方法,这可能需要扩展现有容器或创建一个完全具有所需依赖项的新容器。
https://docs.aws.amazon.com/sagemaker/latest/dg/inference-pipeline-batch.html
- 还有 SageMaker 处理
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。