python - 在 Python 中使用 XGboost_Regressor 可以获得非常好的训练性能,但预测效果很差
问题描述
我一直在尝试在 python 中使用 XGBregressor。这是迄今为止我使用过的最好的 ML 技术之一。但是,在某些数据集中,我的训练 R 平方非常高,但它在预测或测试方面的表现确实很差。我尝试使用 gamma、深度和二次采样来降低模型的复杂性或确保它没有过度拟合,但训练和测试之间仍然存在巨大差异。我想知道是否有人可以帮助我:
下面是我正在使用的代码:
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.30,random_state=100)
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
scaler.fit(X_train)
xgb = xgboost.XGBRegressor(colsample_bytree=0.7,
gamma=0,
learning_rate=0.01,
max_depth=1,
min_child_weight=1.5,
n_estimators=100000,
reg_alpha=0.75,
reg_lambda=0.45,
subsample=0.8,
seed=1000)
这是训练与测试中的表现:
训练:MAE:0.10 R^2:0.99
测试:MAE:1.47 R^2:-0.89
解决方案
XGBoost 倾向于过度拟合数据,因此减少 n_estimators 和 n_depth 并使用训练损失和验证损失之间没有太大差异的特定迭代。
推荐阅读
- c# - 使用 Include 和 ThenInclude 时的 EF Core 引用循环
- azure - 将 Azure 云服务更新到 OS 系列 6
- java - 重复条目:com/google/firebase/iid/zzc.class
- firebase - 在我的应用设置中集成 Google\Firebase 帐户设置
- c# - OPOS CheckHealth 返回 OPOS_EX_NOINPUT (10007),用于 .NET 的 OPOS
- julia - 如何修复 TypeError:在 setindex 中!在微分方程.jl
- java - 当我向文档添加空白页时,当我尝试合并它时出现“resourceDictionary 为空”
- javascript - 将引导程序 4.0.0 alpha 更新到较新版本时导航栏不起作用
- r - 从 igraph 到 ggplot 对象
- javascript - 如何在java脚本中本地保存子节点或父节点