Python XGBoost Error info.labels.size()!=0U(0对0)
我试图使用XGBOOST在python上运行一个回归问题:Python XGBoost Error info.labels.size()!=0U(0对0),python,machine-learning,label,regression,xgboost,Python,Machine Learning,Label,Regression,Xgboost,我试图使用XGBOOST在python上运行一个回归问题: import xgboost global clf clf = XGBRegressor(n_estimators = 500, learning_rate = 0.05, max_depth=6, n_jobs=4, alpha
import xgboost
global clf
clf = XGBRegressor(n_estimators = 500,
learning_rate = 0.05,
max_depth=6,
n_jobs=4,
alpha = 0.1)
clf.fit(X_train, y_train,
early_stopping_rounds = 5,
eval_set = validation, verbose=False)
predicted_test_tr = np.round(clf.predict(X_test))
但经过几次迭代后,它会引发以下错误:
XGBoostError: b'[10:56:23] src/objective/regression_obj.cc:43: Check failed: info.labels_.size() != 0U (0 vs. 0) label set cannot be empty\n\nStack trace returned 7 entries:\n[bt] (0) 0 libxgboost.dylib 0x0000001a1971b7a1 dmlc::StackTrace() + 305\n[bt] (1) 1 libxgboost.dylib 0x0000001a1971b52f dmlc::LogMessageFatal::~LogMessageFatal() + 47\n[bt] (2) 2 libxgboost.dylib 0x0000001a19792d21 xgboost::obj::RegLossObj<xgboost::obj::LinearSquareLoss>::GetGradient(xgboost::HostDeviceVector<float>*, xgboost::MetaInfo const&, int, xgboost::HostDeviceVector<xgboost::detail::GradientPairInternal<float> >*) + 257\n[bt] (3) 3 libxgboost.dylib 0x0000001a19717496 xgboost::LearnerImpl::UpdateOneIter(int, xgboost::DMatrix*) + 1014\n[bt] (4) 4 libxgboost.dylib 0x0000001a1973369f XGBoosterUpdateOneIter + 79\n[bt] (5) 5 libffi.6.dylib 0x0000000110308884 ffi_call_unix64 + 76\n[bt] (6) 6 ??? 0x00007ffee1b29950 0x0 + 140732684998992\n\n'
但仍然报告相同的错误;如何修复它?此代码运行时没有任何问题:
from xgboost import XGBRegressor
clf = XGBRegressor(n_estimators = 500,
learning_rate = 0.05,
max_depth=6,
n_jobs=1,
alpha = 0.1)
import numpy as np
X_train = np.random.uniform(size=(100,10))
y_train = np.zeros(100)
clf.fit(X_train, y_train, verbose=False)
请注意,我没有在clf.fit
中设置am eval。什么是您的变量验证
?它应该是xgboost.DMatrix
和字符串的元组,例如:
dval = xgb.DMatrix(X_val, label=y_val)
validation = (dval, "validation")
请确保列车组和验证组的所有输入(x)都有标签(y)。您可以将输入和标签以DMatrix的形式存储,然后将它们传递给模型。在我的例子中,当数据帧中有非ascii字符时,同样的问题也会发生。如果您已将其移除,它将起作用。或者尝试lightboost gbm,它将抛出一个精确的错误。我认为您应该明确说明Objective函数。这可能有助于解决你的问题。在多标签分类中,如果你指定二元损失作为成本,你会得到一个类似的错误,我试图解决一个回归问题;我知道,我刚刚举了一个例子,我得到了一个与你类似的错误。我的观点是:如果可以的话,在XGBRegressionOri的调用中显式地指定成本函数,在参数部分:objective=“reg:linear”;但它报告了相同的错误。错误是否在
clf=XGBRegressor(…
或clf.fit(…
)处出现?我将验证集定义为测试集的子集:X_test=X[t:]y_test=y[t:]validation=[(X_test,y_test)],如果我使用:dval=xgboost.DMatrix运行代码(X_测试,label=y_测试)validation=(dval,“validation”),它会引发:“'DMatrix'对象不支持索引”
dval = xgb.DMatrix(X_val, label=y_val)
validation = (dval, "validation")