【问题标题】:Why does my XBGoost model have a good accuracy for training and testing dataset, but poor one for predicting an held out dataset?为什么我的 XBGoost 模型对于训练和测试数据集的准确度很高,但在预测保留的数据集时却很差?
【发布时间】:2022-01-05 10:04:40
【问题描述】:

我目前正在研究 XGBoost 回归模型来预测机票预订。 我的问题是我的模型对训练集(大约 96%)和测试集(大约 94%)有很好的准确性,但是当我尝试使用该模型在另一个保留的数据集上预测我的预订时,这个准确性下降到 82%。 我尝试将一些数据从我的测试集中切换到这个保留集,但准确性仍然很差,即使当这些数据在我的测试集中时模型可以有效地预测这些数据。 我认为我做错了什么,但我不知道是什么。 任何帮助将不胜感激,谢谢

这是我的代码中的 XGBoost 模型部分:

import xgboost as xgb
from sklearn.metrics import mean_squared_error

X_conso, y_conso = data_conso2.iloc[:,:-1],data_conso2.iloc[:,-1]

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X_conso, y_conso, test_size=0.3, random_state=20)

d_train = xgb.DMatrix(X_train, label = y_train)
d_test = xgb.DMatrix(X_test, label = y_test)
d_fcst_held_out = xgb.DMatrix(X_fcst_held_out)


params = {'p_colsample_bytree_conso' : 0.9, 
          'p_colsample_bylevel_conso': 0.9,
          'p_colsample_bynode_conso': 0.9,
          'p_learning_rate_conso': 0.3,
          'p_max_depth_conso': 10,
          'p_alpha_conso': 3,
          'p_n_estimators_conso': 10,
          'p_gamma_conso': 0.8}

steps = 100

watchlist = [(d_train, 'train'), (d_test, 'test')]
model = xgb.train(params, d_train, steps, watchlist, early_stopping_rounds = 50)

preds_train = model.predict(d_train)
preds_test = model.predict(d_test)
preds_fcst = model.predict(d_fcst_held_out)

And my accuracy levels :

Error train: 4.524787%
Error test: 5.978759%
Error fcst: 18.008451%

【问题讨论】:

    标签: python xgboost xgbregressor


    【解决方案1】:

    这通常是正常的,看不见的数据通常精度较低。

    为了提高数据的准确性,您可以使用 optuna 来优化您的参数。

    【讨论】:

      猜你喜欢
      • 2020-07-05
      • 2019-07-09
      • 1970-01-01
      • 2015-11-13
      • 1970-01-01
      • 2020-09-29
      • 2013-10-01
      • 2023-02-26
      • 2020-03-26
      相关资源
      最近更新 更多