![](/img/trans.png)
[英]Machine Learning, What are the common techniques for feature engineering and presenting the model?
[英]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 。
有关扩展框架图像的示例,请参阅: 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 。
与上面的方法类似,但是在这种情况下,我们将生成一个单独的 Image 来单独处理我们的数据,然后将该数据传递给我们的原始模型。
根据您的方法,这可能需要扩展现有容器或创建一个完全具有所需依赖项的新容器。
https://docs.aws.amazon.com/sagemaker/latest/dg/inference-pipeline-batch.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.