Sagemaker XGBoost超参数调整错误

时间:2020-10-29 02:52:26

标签: python xgboost amazon-sagemaker hyperparameters

我是Sagemaker的新手,正在尝试为Sagemaker中的xgboost算法设置超参数调整工作。我的数据非常不平衡(多数类为98%,少数类为2%),我想使用“ scale_pos_weight”参数,但是会发生以下错误。

ClientError: An error occurred (ValidationException) when calling the CreateHyperParameterTuningJob operation: The hyperparameter tuning job that you requested has the following untunable hyperparameters: [scale_pos_weight]. For the algorithm, ---------------.us-east-1.amazonaws.com/xgboost:1, you can tune only [colsample_bytree, lambda, eta, max_depth, alpha, num_round, colsample_bylevel, subsample, min_child_weight, max_delta_step, gamma]. Delete untunable hyperparameters.  

我已经升级了sagemaker软件包,重新启动了内核(我正在使用虚拟笔记本电脑)和实例,但是问题仍然存在。

有人知道为什么会发生此错误以及如何解决该错误吗?感谢您的帮助。

这是我在AWS的一个示例中遵循的代码。

sess = sagemaker.Session()
container = get_image_uri(region, 'xgboost', '1.0-1')

xgb = sagemaker.estimator.Estimator(container,
                                    role, 
                                    train_instance_count=1, 
                                    train_instance_type='ml.m4.4xlarge',
                                    output_path='s3://{}/{}/output'.format(bucket, prefix),
                                    sagemaker_session=sess)

xgb.set_hyperparameters(eval_metric='auc',
                        objective='binary:logistic',
                        num_round=100,
                        rate_drop=0.3,
                        tweedie_variance_power=1.4)

hyperparameter_ranges = {'eta': ContinuousParameter(0, 1),
                        'min_child_weight': ContinuousParameter(1, 10),
                        'scale_pos_weight' : ContinuousParameter(700, 800),
                        'alpha': ContinuousParameter(0, 2),
                        'max_depth': IntegerParameter(1, 10),
                        'colsample_bytree' : ContinuousParameter(0.1, 0.9)
                        }
objective_metric_name = 'validation:auc'

tuner = HyperparameterTuner(xgb,
                            objective_metric_name,
                            hyperparameter_ranges,
                            max_jobs=10,
                            max_parallel_jobs=2)

s3_input_train = sagemaker.s3_input(s3_data='s3://{}/{}/train'.format(bucket, prefix), content_type='csv')
s3_input_validation = sagemaker.s3_input(s3_data='s3://{}/{}/validation/'.format(bucket, prefix), content_type='csv')

tuner.fit({'train': s3_input_train, 'validation': s3_input_validation}, include_cls_metadata=False)

1 个答案:

答案 0 :(得分:0)

基于Sagemaker开发人员文档https://docs.aws.amazon.com/sagemaker/latest/dg/xgboost-tuning.html,超参数scale_pos_weight是不可调整的。您可以调整的唯一参数在链接中给出。