1

In running xgboost with Python I run into exceptions:

For a reproducible example:

import sklearn
from sklearn import datasets
data, labels = sklearn.datasets.load_diabetes(return_X_y= True)
labels = (labels > 100) * 1
X_train = data[:300, :]
y_train = labels[:300]
X_test = data[300:,:]
y_test = labels[300:]
dtrain = xgb.DMatrix(data = X_train, label = np.array(y_train), feature_names =['age',
  'sex',
  'bmi',
  'bp',
  's1',
  's2',
  's3',
  's4',
  's5',
  's6'])
dtest = xgb.DMatrix(data = X_test, label = np.array(y_test), feature_names = ['age',
  'sex',
  'bmi',
  'bp',
  's1',
  's2',
  's3',
  's4',
  's5',
  's6'])
param = {'colsample_bytree': 0.7,
 'eta': 0.3,
 'gamma': 3.0,
 'max_depth': 6,
 'min_child_weight': 4.0,
 'objective': 'binary:logistic',
 'reg_alpha': 0.3,
 'reg_lambda': 0.3,
 'silent': 0,
 'subsample': 0.8}
watchlist = [(dtest, 'eval'), (dtrain, 'train')]
num_boost_round = 100
bst = xgb.train(params = param, watchlist = watchlist , dtrain = dtrain, num_boost_round = num_boost_round,   \
                    early_stopping_rounds = True)

This results in the exception:

TypeError: train() got an unexpected keyword argument 'watchlist'

If I remove watchlist I get another exception:

bst = xgb.train(params = param, dtrain = dtrain, num_boost_round = num_boost_round,   \
                    early_stopping_rounds = True)
IndexError: list index out of range

1 Answer 1

1

from doc

xgboost.train(params, dtrain, num_boost_round=10, evals=(), obj=None, 
feval=None, maximize=False, early_stopping_rounds=None, evals_result=None, 
verbose_eval=True, xgb_model=None, callbacks=None, learning_rates=None)

Train a booster with given parameters.

Parameters:

params (dict) – Booster params.

dtrain (DMatrix) – Data to be trained.

num_boost_round (int) – Number of boosting iterations.

evals (list of pairs (DMatrix, string)) – List of items to be evaluated during 
training, this allows user to watch performance on the validation set.

the parameter is not called watchlist but evals.

just changing that got me the following:

[0] eval-error:0.274648 train-error:0.253333
Multiple eval metrics have been passed: 'train-error' will be used for 
early stopping.

Will train until train-error hasn't improved in True rounds.
[1] eval-error:0.211268 train-error:0.223333
[2] eval-error:0.204225 train-error:0.203333
[3] eval-error:0.225352 train-error:0.203333
Stopping. Best iteration:
[2] eval-error:0.204225 train-error:0.203333
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.