我正在尝试使用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]
我进行了交叉验证以获取最佳模型和最佳轮次。我在交叉验证中获得了0.994的AUC分数,并在验证集中获得了类似的分数。
但是当我对测试集进行预测时,结果非常糟糕。我确信训练集被完美地采样了。
需要调整哪些参数?问题的原因是什么?是否应该重新采样数据集以减少最高类别?