繁体   English   中英

如何评估xgboost分类model稳定性

[英]How to evaluate the xgboost classification model stability

我有:

  1. Python xgboost 分类 model
  2. 自 2018 年初以来的每周数据集(分类基础)。每个数据集大约有 10 万行和 70 列(特征)。
  3. 通过 xgboost model(使用逻辑回归)对数据集的每周预测结果,格式为:
- date of modelling
- items
- test_auc_mean for each item (in percentage).

自 2018 年 1 月以来,总共有大约 100 个数据集和 100 个预测结果。

为了评估 model,我使用以下指标:

-auc

-混淆矩阵

-准确性

param = {
    'num_parallel_tree':num_parallel_tree,
    'subsample':subsample,
    'colsample_bytree':colsample_bytree,
    'objective':objective, 
    'learning_rate':learning_rate, 
    'eval_metric':eval_metric, 
    'max_depth':max_depth,
    'scale_pos_weight':scale_pos_weight,
    'min_child_weight':min_child_weight,
    'nthread':nthread,
    'seed':seed
}

bst_cv = xgb.cv(
    param, 
    dtrain,  
    num_boost_round=n_estimators, 
    nfold = nfold,
    early_stopping_rounds=early_stopping_rounds,
    verbose_eval=verbose,
    stratified = stratified
)

test_auc_mean = bst_cv['test-auc-mean']
best_iteration = test_auc_mean[test_auc_mean == max(test_auc_mean)].index[0]

bst = xgb.train(param, 
                dtrain, 
                num_boost_round = best_iteration)

best_train_auc_mean = bst_cv['train-auc-mean'][best_iteration]
best_train_auc_mean_std = bst_cv['train-auc-std'][best_iteration]

best_test_auc_mean = bst_cv['test-auc-mean'][best_iteration]
best_test_auc_mean_std = bst_cv['test-auc-std'][best_iteration]

print('''XGB CV model report
Best train-auc-mean {}% (std: {}%) 
Best test-auc-mean {}% (std: {}%)'''.format(round(best_train_auc_mean * 100, 2), 
                                          round(best_train_auc_mean_std * 100, 2), 
                                          round(best_test_auc_mean * 100, 2), 
                                          round(best_test_auc_mean_std * 100, 2)))

y_pred = bst.predict(dtest)
tn, fp, fn, tp = confusion_matrix(y_test, y_pred>0.9).ravel()


print('''
     | neg | pos |
__________________
true_| {}  | {}  |
false| {}  | {}  |
__________________

'''.format(tn, tp, fn, fp))

predict_accuracy_on_test_set = (tn + tp)/(tn + fp + fn + tp)
print('Test Accuracy: {}%'.format(round(predict_accuracy_on_test_set * 100, 2)))

model 给了我一般的图片(通常,auc 介于.94 和.96 之间)问题是预测某些特定项目的可变性非常高(今天一个项目是正面的,明天一个项目是负面的,后天明天 - 再次积极)

我想评估模型的稳定性。 换句话说,我想知道它生成了多少具有可变结果的项目。 最后,我想确保 model 将产生稳定的结果,波动最小。 你有一些想法如何做到这一点?

这正是交叉验证的目标。 既然你已经这样做了,你只能评估你的评估指标的标准差,你也已经这样做了......

  1. 你可以尝试一些新的指标,比如精确度、召回率、f1 分数或 fn 分数来以不同的方式衡量成功和失败,但看起来你几乎没有解决方案。 您取决于此处的数据输入:s

  2. 您可以花一些时间来训练人口分布,并尝试确定人口的哪一部分随着时间的推移而波动。

  3. 您还可以尝试预测概率而不是分类来评估 model 是否远高于其阈值。

最后两个解决方案更像是侧面解决方案。 :(

1 个项目的预测概率 (mean-auc 格温达尔,谢谢。 您能否指定您提到的两种方法。 1)如何训练人口分布? 通过 K-Clustering 或其他无监督学习方法? 2)例如我预测的_proba(1个特定项目的图表-在附件中)。 如何评估 model 是否远高于其阈值? 通过比较每个项目的 predict_proba 与它的真实 label(例如 predict_proba = 0.5 和 label = 1)?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM