我正在尝试在数据集上训练 xgboost 模型X-train, X_test
。代码:
xgb_params = {
"objective": "multi:softmax",
"eta": 0.3,
"num_class": 62,
"max_depth": 10,
"nthread": 4,
"eval_metric": "merror",
"print.every.n": 1
#"silent": 1
}
num_rounds = 2
mask = np.random.choice([False, True], len(X_train), p=[0.75, 0.25])
not_mask = [not i for i in mask]
dtrain = xgb.DMatrix(X_train[not_mask], label=y[not_mask])
dtrain_watch = xgb.DMatrix(X_train[mask], label=y[mask])
dtest = xgb.DMatrix(X_test)
gbdt = xgb.train(xgb_params, dtrain, num_rounds, dtrain_watch)
preds = gbdt.predict(dtest)
但我收到错误:TypeError: 'DMatrix' object is not iterable
在倒数第二行。
需要做什么?
np.array
编辑:如果我故意打字,我会得到TypeError: iteration over a 0-d array
编辑2:如果我DMatrix
完全避免这种方式:watchlist = list(np.append(X_train[mask], np.matrix(y[mask]).transpose(), axis=1))
我得到另一个错误
xgboost.py", line 340, in __init__
raise TypeError('invalid cache item: {}'.format(type(d).__name__))
TypeError: invalid cache item: matrix