作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在毫无问题地运行以下代码:
churn_dmatrix = xgb.DMatrix(data = class_data.iloc[:, :-1], label = class_data.Churn)
params = {'objective' : 'binary:logistic' , 'max_depth' : 4}
cv_results = xgb.cv(dtrain = churn_dmatrix, params = params, nfold = 4, num_boost_round = 1, metrics = 'error', \
as_pandas = True)
print(cv_results)
train-error-mean train-error-std test-error-mean test-error-std
0 0.395833 0.108253 0.375 0.414578
但是,当我将指标更改为“auc”时,我收到一条错误消息:
cv_results = xgb.cv(dtrain = churn_dmatrix, params = params, nfold = 4, num_boost_round = 5, metrics = 'auc', \
as_pandas = True)
---------------------------------------------------------------------------
XGBoostError Traceback (most recent call last)
<ipython-input-102-ea99ef0705b5> in <module>()
----> 1 cv_results = xgb.cv(dtrain = churn_dmatrix, params = params, nfold = 4, num_boost_round = 5, metrics = 'auc', as_pandas = True)
C:\ProgramData\Anaconda3\lib\site-packages\xgboost\training.py in cv(params, dtrain, num_boost_round, nfold, stratified, folds, metrics, obj, feval, maximize, early_stopping_rounds, fpreproc, as_pandas, verbose_eval, show_stdv, seed, callbacks, shuffle)
405 for fold in cvfolds:
406 fold.update(i, obj)
--> 407 res = aggcv([f.eval(i, feval) for f in cvfolds])
408
409 for key, mean, std in res:
C:\ProgramData\Anaconda3\lib\site-packages\xgboost\training.py in <listcomp>(.0)
405 for fold in cvfolds:
406 fold.update(i, obj)
--> 407 res = aggcv([f.eval(i, feval) for f in cvfolds])
408
409 for key, mean, std in res:
C:\ProgramData\Anaconda3\lib\site-packages\xgboost\training.py in eval(self, iteration, feval)
220 def eval(self, iteration, feval):
221 """"Evaluate the CVPack for one iteration."""
--> 222 return self.bst.eval_set(self.watchlist, iteration, feval)
223
224
C:\ProgramData\Anaconda3\lib\site-packages\xgboost\core.py in eval_set(self, evals, iteration, feval)
953 dmats, evnames,
954 c_bst_ulong(len(evals)),
--> 955 ctypes.byref(msg)))
956 res = msg.value.decode()
957 if feval is not None:
C:\ProgramData\Anaconda3\lib\site-packages\xgboost\core.py in _check_call(ret)
128 """
129 if ret != 0:
--> 130 raise XGBoostError(_LIB.XGBGetLastError())
131
132
XGBoostError: b'[14:27:23] src/metric/rank_metric.cc:135: Check failed: !auc_error AUC: the dataset only contains pos or neg samples'
似乎所有的预测都是正面的或负面的。我对么?有什么我可以做的吗?
最佳答案
当 xgboost 尝试拆分为训练/验证并且在其中一个拆分中它没有负样本或正样本(无论是在训练集还是验证集中)时,问题就出现了。
我看到您可以采用 2 种快速方法:
99/1
的乘积)。关于python-3.x - xgboost 错误 : Check failed: ! auc_error AUC:数据集仅包含 pos 或 neg 样本',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51572501/
我正在毫无问题地运行以下代码: churn_dmatrix = xgb.DMatrix(data = class_data.iloc[:, :-1], label = class_data.Churn
我是一名优秀的程序员,十分优秀!