rank_metric: Check failed: preds.Size() == info.labels_.Size() label size predict size not match

问题场景: python xgboost进行多分类问题时,会遇到上述问题;

问题原因: 是多分类时使用的eval_metric不能是auc

解决办法: 需要更改为mlogloss

xgboost参数配置

params = {
            # General Parameters
            'booster': 'gbtree',
            'nthread': os.cpu_count() - 1,
            # Parameters for Tree Booster
            'eta': 0.01,  # alias: learning_rate
            'gamma': 0.1,  # alias: min_split_loss
            'max_depth': 5,
            'min_child_weight': 1.1,
            'subsample': 0.7,
            'colsample_bytree': 0.7,
            'colsample_bylevel': 0.7,
            'lambda': 10,  # alias: reg_alpha
            'alpha': 0,  # alias:reg_alpha
            'tree_method': 'gpu_hist',
            # Learning Task Parameters
            'objective': 'multi:softmax',  # 2分类binary:logistic,多分类multi:softmax
            'num_class': 5,
            'eval_metric': 'auc', #更改为'mlogloss'问题解决
            'seed': 0,
        }

参考博客:
[1] https://blog.csdn.net/lusic01/article/details/84873899
[2] https://github.com/dmlc/xgboost/issues/1143
[3] https://stackoverflow.com/questions/45261638/xgboosterror-b191258-src-metric-rank-metric-cc89-check-failed-preds-si

你可能感兴趣的:(Machine,Learning)