我正在使用Amazon Sagemaker运行xgboost模型以下注最佳超参数组合。我必须使用sagemaker实现而不是笔记本替代测试它是否比gridsearch运行得更快。 我的问题是如何在循环中完成这项工作。有任何想法吗? 我的理解是我必须用不同的组合编写许多工作。 我试过这个测试:
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读取基本信息和超级参数列表的方式。
好处是它有效。不好的是,这一次训练一个模型。我希望所有这些组合能够同时运行。 我怎么能这样做?