问题
I am trying to train a model using the sagemaker library. So far, my code is the following:
container = get_image_uri(boto3.Session().region_name,
'xgboost',
repo_version='0.90-1')
estimator = sagemaker.estimator.Estimator(container,
role = 'AmazonSageMaker-ExecutionRole-20190305TXXX',
train_instance_count = 1,
train_instance_type = 'ml.m4.2xlarge',
output_path = 's3://antifraud/production/',
hyperparameters = {'num_rounds':'400',
'objective':'binary:logistic',
'eval_metric':'error@0.1'})
train_config = training_config(estimator=estimator,
inputs = {'train':'s3://antifraud/production/train',
'validation':'s3://-antifraud/production/validation'})
And I get an error parsing the hyperparameters. This commands gives me a configuration JSON output in the console. I have been able to run a training job using boto3 with the configuration as Json, so I have figured out that the thing I am missing in my json configuration generated by my code is the content_type parameter, which should be there as follow:
"InputDataConfig": [
{
"ChannelName": "train",
"DataSource": {
"S3DataSource": {
"S3DataType": "S3Prefix",
"S3Uri": "s3://antifraud/production/data/train",
"S3DataDistributionType": "FullyReplicated"
}
},
"ContentType": "text/csv",
"CompressionType": "None"
},
{
"ChannelName": "validation",
"DataSource": {
"S3DataSource": {
"S3DataType": "S3Prefix",
"S3Uri": "s3://antifraud/production/validation",
"S3DataDistributionType": "FullyReplicated"
}
},
"ContentType": "text/csv",
"CompressionType": "None"
}
]
I have tried coding content_type = 'text/csv' in container, estimator and train_config as parameter and also inside inputs as another key of the dictionary, with no success. How could I make this work?
回答1:
I have solved it using s3_input objects:
s3_input_train = sagemaker.s3_input(s3_data='s3://antifraud/production/data/{domain}-{product}-{today}/train_data.csv',
content_type='text/csv')
s3_input_validation = sagemaker.s3_input(s3_data='s3://antifraud/production/data/{domain}-{product}-{today}/validation_data.csv',
content_type='text/csv')
train_config = training_config(estimator=estimator,
inputs = {'train':s3_input_train,
'validation':s3_input_validation})
来源:https://stackoverflow.com/questions/57908395/how-can-i-specify-content-type-in-a-training-job-of-xgboost-from-sagemaker-in-py