Sagemaker XGBoost超参数调整错误

2024-09-25 04:34:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我是Sagemaker的新手,正在尝试在Sagemaker中为xgboost算法设置超参数调优工作。我有非常不平衡的数据(98%的多数类,2%的少数类),我想使用“scale\u pos\u 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软件包,重新启动了内核(我正在使用juptyer笔记本),并安装了实例,但问题仍然存在

有没有人知道为什么会发生这种错误,以及我如何修复它?我感谢你的帮助

下面是我在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)

Tags: theposinputs3trainmaxvalidationsagemaker