我正在尝试使用 XGBoost 模型获得分类值。
但是,当我声明 XGBoost 模型时出现错误。
我该如何解决这个错误?
train = pd.read_csv("./data/train.csv")
test_x = pd.read_csv("./data/test.csv")
train_y = train['Y']
train_x = train.drop('Y', axis=1)
kf = KFold(n_splits=4, shuffle=True, random_state=71)
tr_idx, va_idx = list(kf.split(train_x))[0]
tr_x, va_x = train_x.iloc[tr_idx], train_x.iloc[va_idx]
tr_y, va_y = train_y.iloc[tr_idx], train_y.iloc[va_idx]
dtrain = xgb.DMatrix(tr_x, label=tr_y)
dvalid = xgb.DMatrix(va_x, label=va_y),
dtest = xgb.DMatrix(test_x)
print('-' * 10)
params = {'objective' : 'binary:logistic',
'eval_metric' : 'logloss',
'verbosity': 0, 'random_state' : 71}
num_round = 10000
watch_list = [(dtrain, 'train'),(dvalid, 'eval')]
model = xgb.train(params, dtrain, num_round, watch_list) ← error occured here
并且错误信息在这里。
TypeError: ('invalid cache item: tuple', [<xgboost.core.DMatrix object at 0x000001B9D6930190>, <xgboost.core.DMatrix object at 0x000001B9D6930190>, (<xgboost.core.DMatrix object at 0x000001B9DBBCA880>,)])