首页 > 解决方案 > 如何减少 xgboost 中的误报?

问题描述

我的数据集平均分为 0 和 1 个分类器。总共 100,000 个数据点,其中 50,000 个被归类为 0,另外 50,000 个被归类为 1。我进行了 80/20 拆分来训练/测试数据并返回 98% 的准确度分数。然而,在查看混淆矩阵时,我有很多误报。一般来说,我是 xgboost 和决策树的新手。我可以更改哪些设置XGBClassifier以减少误报的数量,甚至有可能吗?谢谢你。

在此处输入图像描述

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.2, random_state=0, stratify=y) # 80% training and 20% test

model = xgb.XGBClassifier(base_score=0.5, booster='gbtree', colsample_bylevel=1,
              colsample_bynode=1, colsample_bytree=1, gamma=0, gpu_id=-1,
              importance_type='gain', interaction_constraints='',
              learning_rate=0.1, max_delta_step=0, max_depth=9,
              min_child_weight=1, missing=None, monotone_constraints='()',
              n_estimators=180, n_jobs=4, num_parallel_tree=1, random_state=0,
              reg_alpha=0, reg_lambda=1, scale_pos_weight=1, subsample=1,
              tree_method='exact', use_label_encoder=False,
              validate_parameters=1, verbosity=None)

model.fit(X_train,
           y_train,
           verbose = True, 
           early_stopping_rounds=10,
           eval_metric = "aucpr",
           eval_set = [(X_test, y_test)])

plot_confusion_matrix(model,
                      X_test,
                      y_test,
                      values_format='d',
                      display_labels=['Old Forests', 'Not Old Forests'])

标签: python-3.xscikit-learnxgboost

解决方案


是 如果您正在寻找一个简单的修复方法,您可以降低 scale_pos_weight 的值。即使您的数据集是平衡的,这也会降低误报率。

要获得更强大的修复,您将需要运行超参数调整搜索。特别是你应该尝试不同的值:scale_pos_weight、alpha、lambda、gamma 和 min_child_weight。因为它们对模型的保守程度影响最大。


推荐阅读