我正在使用 Amazon Sagemaker 来运行 xgboost 模型,以便押注最佳的超参数组合。我必须使用 sagemaker 实现而不是笔记本替代品来测试它是否比网格搜索运行得更快。我的问题是如何使这项工作循环进行。有任何想法吗?我的理解是,我必须用不同的组合编写大量工作。我试过这个作为测试:
for i in range (1,3):
for j in range (13,15):
job_name = 'regression' + '-'+str(i) +"-"+str(j)+"-" +strftime("%Y-%m-%d-%H-%M-%S", gmtime())
job_name_params = copy.deepcopy(parameters_xgboost)
job_name_params['TrainingJobName'] = job_name
job_name_params['OutputDataConfig']['S3OutputPath']= "....."
job_name_params['HyperParameters']['objective'] = "reg:linear"
job_name_params['HyperParameters']['silent'] = "0"
job_name_params['HyperParameters']['max_depth'] = str(i)
job_name_params['HyperParameters']['min_child_weight'] = str(j)
job_name_params['HyperParameters']['eta'] = "0.01"
job_name_params['HyperParameters']['num_round'] = "1000"
job_name_params['HyperParameters']['subsample'] = "0.5"
job_name_params['HyperParameters']['colsample_bytree'] = "0.5"
sm = boto3.Session().client('.....')
sm.create_training_job(**job_name_params)
sm.get_waiter('training_job_completed_or_stopped').wait(TrainingJobName=job_name)
status = sm.describe_training_job(TrainingJobName=job_name)['TrainingJobStatus']
print("Training job ended with status: " + status)
parameters_xgboost 是 Sagemaker 读取基本信息和超参数列表的方式。
好消息是它有效。不好的是,这一次只训练一个模型。我希望所有这些组合同时运行。我怎样才能做到这一点?