【发布时间】:2018-12-13 21:45:34
【问题描述】:
我正在尝试在非常不平衡的数据集上使用 LightGBM 构建分类器。不平衡在比率97:3,即:
Class
0 0.970691
1 0.029309
我使用的参数和训练代码如下所示。
lgb_params = {
'boosting_type': 'gbdt',
'objective': 'binary',
'metric':'auc',
'learning_rate': 0.1,
'is_unbalance': 'true', #because training data is unbalance (replaced with scale_pos_weight)
'num_leaves': 31, # we should let it be smaller than 2^(max_depth)
'max_depth': 6, # -1 means no limit
'subsample' : 0.78
}
# Cross-validate
cv_results = lgb.cv(lgb_params, dtrain, num_boost_round=1500, nfold=10,
verbose_eval=10, early_stopping_rounds=40)
nround = cv_results['auc-mean'].index(np.max(cv_results['auc-mean']))
print(nround)
model = lgb.train(lgb_params, dtrain, num_boost_round=nround)
preds = model.predict(test_feats)
preds = [1 if x >= 0.5 else 0 for x in preds]
我运行 CV 以获得最佳模型和最佳回合。我在 CV 上得到了 0.994 AUC,在验证集中得到了相似的分数。
但是当我在测试集上进行预测时,我得到了非常糟糕的结果。我确信训练集被完美地采样了。
需要调整哪些参数。?问题的原因是什么。?我应该重新采样数据集以减少最高类别吗?
【问题讨论】:
-
您用于预测的确切代码是什么?
-
我现在将更新问题以显示代码
-
请包括您的数据和预测的(短)样本,以及与类不平衡相关的任何信息
标签: python machine-learning classification auc lightgbm