Python SageMaker模型中的自定义特征工程
我在SageMaker中使用批处理转换来调用存储的XGBoost模型,并对存储在S3中的数据进行评分。然而,在调用该模型之前,我必须对列进行一些转换 以下是用于批处理转换的代码:Python SageMaker模型中的自定义特征工程,python,amazon-web-services,amazon-sagemaker,Python,Amazon Web Services,Amazon Sagemaker,我在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
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
}
)
batch_input='s3://{}/{}/batch/test_data_batch.csv'。格式(bucket,前缀)#用于预测的测试数据
batch_output='s3://{}/{}/batch/batch推断/test_data_batch.csv.out'。格式(bucket,前缀)
Modelname=''#我们已经拥有的模型名称
transformJobName='DEMO xgboost CHARNER call batch'+strftime(“%Y-%m-%d-%H-%m-%S”,gmtime())
client=bot3.client('sagemaker')
create\u batch=client.create\u transform\u作业(
TransformJobName=TransformJobName,
ModelName=ModelName,
MaxConcurrentTransforms=0,
MaxPayloadInMB=6,
BatchStrategy='MultiRecord',
变换输入={
“数据源”:{
“S3DataSource”:{
“S3DataType”:“S3Prefix”,
“S3Uri”:批处理输入
}
},
“ContentType”:“text/csv”,
“压缩类型”:“无”,
“拆分类型”:“行”
},
变压器输出={
“S3OutputPath”:批处理输出,
“AssembleWith”:“行”
},
转化资源={
'InstanceType':'ml.m4.xlarge',
“InstanceCount”:1
}
)
在使用XGBoost模型运行批处理转换之前,如何调用功能工程Python函数来转换数据?一些指针会有帮助。谢谢。对迟来的回复表示歉意 我相信有几种方法可以在SageMaker中与批处理一起进行一些预处理 我假设您使用的是SageMaker在中提供的XGBoost映像: