aws / aws/amazon-sagemaker-examples

using monotonicity constraints - XGBoost as a built-in algorithm

Open
#3,428 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
11k
Forks
7k
Avg merge
8h 29m
Merged PRs (30d)
8

Description

Let is assume I have a dataset with 3 independent valiables/predictors/features. So far I used code along those lines successfully:

```
hyperparameters = {
'max_depth': '10',
'num_round': '100',
'objective': 'count:poisson'
}

output_path = 's3://{}/{}/output'.format(s3_bucket_name, s3_prefix)

estimator = sagemaker.estimator.Estimator(image_uri=sagemaker.image_uris.retrieve("xgboost", region_name, "1.5-1"),
hyperparameters=hyperparameters,
role=role_arn,
instance_count=1,
instance_type='ml.m5.2xlarge',
#instance_type='local',
volume_size=1, # 1 GB
output_path=output_path)

estimator.fit({'train': s3_input_train, 'validation': s3_input_val})
```
However, when I try to impose a monotonicity constraint on the 2nd feature like so:

```
hyperparameters = {
'max_depth': '10',
'num_round': '100',
'objective': 'count:poisson',
'tree_method': 'exact',
'monotone_constraints': '(0,-1,0)'
}

output_path = 's3://{}/{}/output'.format(s3_bucket_name, s3_prefix)

estimator = sagemaker.estimator.Estimator(image_uri=sagemaker.image_uris.retrieve("xgboost", region_name, "1.5-1"),
hyperparameters=hyperparameters,
role=role_arn,
instance_count=1,
instance_type='ml.m5.2xlarge',
#instance_type='local',
volume_size=1, # 1 GB
output_path=output_path)

estimator.fit({'train': s3_input_train, 'validation': s3_input_val})
```

Any ideas? Maybe this is not possible for the "built-in algorithm"?

PS:

Errors:

`Traceback (most recent call last):
File "c:\Repos\ds_cs_ipt2\modeling\fit_occupancy_model_in_sagemaker.py", line 67, in
estimator.fit({'train': s3_input_train, 'validation': s3_input_val})
File "C:\Python\Python310\lib\site-packages\sagemaker\estimator.py", line 956, in fit
self.latest_training_job.wait(logs=logs)
File "C:\Python\Python310\lib\site-packages\sagemaker\estimator.py", line 1957, in wait
self.sagemaker_session.logs_for_job(self.job_name, wait=True, log_type=logs)
File "C:\Python\Python310\lib\site-packages\sagemaker\session.py", line 3798, in logs_for_job
self._check_job_status(job_name, description, "TrainingJobStatus")
File "C:\Python\Python310\lib\site-packages\sagemaker\session.py", line 3336, in _check_job_status
raise exceptions.UnexpectedStatusException(
sagemaker.exceptions.UnexpectedStatusException: Error for Training job sagemaker-xgboost-2022-05-25-11-11-03-685: Failed. Reason: AlgorithmError: framework error:
Traceback (most recent call last):
File "/miniconda3/lib/python3.7/site-packages/sagemaker_xgboost_container/algorithm_mode/train.py", line 233, in train_job
feval=configured_feval, callbacks=callbacks, xgb_model=xgb_model, verbose_eval=False)
File "/miniconda3/lib/python3.7/site-packages/xgboost/training.py", line 196, in train
early_stopping_rounds=early_stopping_rounds)
File "/miniconda3/lib/python3.7/site-packages/xgboost/training.py", line 51, in _train_internal
bst = Booster(params, [dtrain] + [d[0] for d in evals])
File "/miniconda3/lib/python3.7/site-packages/xgboost/core.py", line 1334, in __init__
params = self._configure_constraints(params)
File "/miniconda3/lib/python3.7/site-packages/xgboost/core.py", line 1400, in _configure_constraints
] = self._transform_monotone_constrains(value)
File "/miniconda3/lib/python3.7/site-packages/xgboost/core.py", line 1361, in _transform_monotone_constrains
constrained_features = set(value.keys`

Contributor guide

Open the contributing guide

Research direction

Start at the SageMaker Estimator.fit call and inspect how the listed hyperparameters, especially monotone_constraints, are passed to the XGBoost 1.5-1 built-in image. Reproduce the failed training job using the provided three-feature configuration and determine whether the constraint format is supported; done means the job trains successfully or the limitation is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python
Domain
cloud, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.