python - XGBoost 错误 info.labels.size() != 0U (0 vs. 0)

标签 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 = 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'

我尝试使用以下方法转换输入和输出:

.apply(pd.to_numeric)

但是仍然报同样的错误;怎么解决?

最佳答案

此代码运行没有任何问题:

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")

关于python - XGBoost 错误 info.labels.size() != 0U (0 vs. 0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51187225/

相关文章:

python - 分箱后无法访问数据帧的 groupby 对象的各个列

python - 加速或矢量化 pandas 应用函数 - 需要有条件地应用函数

python - 运行时错误: b'no arguments in initialization list'

machine-learning - 我们应该何时何地使用这些 keras LSTM 模型

javascript - 如何更改标签的文本?

search - 在editedField BlackBerry中显示默认文本

python - 如何刷新已经运行的 python 程序的 linux stdio-redirect-buffer?

python - 从其他 Cython 声明文件导入外部声明

algorithm - 对社交网络中的 friend 进行分类

swift - 如何在 Swift 中正确设置字符串格式以填充标签