我正在尝试为 Mercedes Greener Manufacturing 数据集建立一个通用模型。所以,我正在尝试使用 XGBoost Regressor 来达到同样的效果。我使用了一个 1-100 的循环作为训练测试集的种子,以便获得更好的采样。我使用 PCA 将尺寸减小到 8 。
如何使用 xgboost 进行微调,以免我得到过拟合的模型?
X_train,X_test,y_train,y_test = train_test_split(X_pc,
y,
test_size=0.2,
random_state = i)
model = XGBRegressor()
model.fit(X_train,y_train)
train=model.score(X_train,y_train)
test=model.score(X_test,y_test)
输出
TEST: 0.28278595203767265 TRAIN: 0.9041892366322192 RS: 0
TEST: 0.3803514386218507 TRAIN: 0.9099759411069458 RS: 1
TEST: 0.3357132066270113 TRAIN: 0.9113739827130357 RS: 2
TEST: 0.3003256802391573 TRAIN: 0.901560899846001 RS: 3
TEST: 0.3769044561739856 TRAIN: 0.9034886060173257 RS: 4
TEST: 0.3449160536081909 TRAIN: 0.9092295020552124 RS: 5
TEST: 0.43083817087609166 TRAIN: 0.8957931397175393 RS: 6
TEST: 0.27375366705147564 TRAIN: 0.912349291318306 RS: 7
TEST: 0.39315883169376264 TRAIN: 0.9090768492254802 RS: 8
TEST: 0.38714220182913905 TRAIN: 0.9089864030990132 RS: 9
TEST: 0.37089065589124093 TRAIN: 0.9099379400411342 RS: 10
TEST: 0.3785854487827084 TRAIN: 0.9080405667805768 RS: 11
TEST: 0.29249852154319345 TRAIN: 0.9057747080596891 RS: 12
TEST: 0.34881642748048425 TRAIN: 0.9077565004654295 RS: 13