title: Sagemaker Hyperparameter Optimization XGBoost
body: <p>I am trying to build a hyperparameter optimization job in Amazon Sagemaker, in python, but something is not working. Here is what I have:</p>
  
  <pre><code>sess = sagemaker.Session()
  
  xgb = sagemaker.estimator.Estimator(containers[boto3.Session().region_name],
                                      role, 
                                      train_instance_count=1, 
                                      train_instance_type='ml.m4.4xlarge',
                                      output_path=output_path_1,
                                      base_job_name='HPO-xgb',
                                      sagemaker_session=sess)
  
  from sagemaker.tuner import HyperparameterTuner, IntegerParameter, CategoricalParameter, ContinuousParameter    
  
  hyperparameter_ranges = {'eta': ContinuousParameter(0.01, 0.2),
                           'num_rounds': ContinuousParameter(100, 500),
                           'num_class':  4,
                           'max_depth': IntegerParameter(3, 9),
                           'gamma': IntegerParameter(0, 5),
                           'min_child_weight': IntegerParameter(2, 6),
                           'subsample': ContinuousParameter(0.5, 0.9),
                           'colsample_bytree': ContinuousParameter(0.5, 0.9)}
  
  objective_metric_name = 'validation:mlogloss'
  objective_type='minimize'
  metric_definitions = [{'Name': 'validation-mlogloss',
                         'Regex': 'validation-mlogloss=([0-9\\.]+)'}]
  
  tuner = HyperparameterTuner(xgb,
                              objective_metric_name,
                              objective_type,
                              hyperparameter_ranges,
                              metric_definitions,
                              max_jobs=9,
                              max_parallel_jobs=3)
  
  tuner.fit({'train': s3_input_train, 'validation': s3_input_validation}) 
  </code></pre>
  
  <p>And the error I get is: </p>
  
  <pre><code>AttributeError: 'str' object has no attribute 'keys'
  </code></pre>
  
  <p>The error seems to come from the <code>tuner.py</code> file:</p>
  
  <pre><code>----&gt; 1 tuner.fit({'train': s3_input_train, 'validation': s3_input_validation})
  
  ~/anaconda3/envs/python3/lib/python3.6/site-packages/sagemaker/tuner.py in fit(self, inputs, job_name, **kwargs)
      144             self.estimator._prepare_for_training(job_name)
      145 
  --&gt; 146         self._prepare_for_training(job_name=job_name)
      147         self.latest_tuning_job = _TuningJob.start_new(self, inputs)
      148 
  
  ~/anaconda3/envs/python3/lib/python3.6/site-packages/sagemaker/tuner.py in _prepare_for_training(self, job_name)
      120 
      121         self.static_hyperparameters = {to_str(k): to_str(v) for (k, v) in self.estimator.hyperparameters().items()}
  --&gt; 122         for hyperparameter_name in self._hyperparameter_ranges.keys():
      123             self.static_hyperparameters.pop(hyperparameter_name, None)
      124 
  
  AttributeError: 'list' object has no attribute 'keys'                           
  </code></pre>