gpt4 book ai didi

python - 如何从 xgboost CV 中获取经过训练的模型?

转载 作者:行者123 更新时间:2023-12-05 00:44:35 26 4
gpt4 key购买 nike

我正在运行以下代码:

params = {"objective":"reg:squarederror",'colsample_bytree': 0.3,'learning_rate': 0.15,
'max_depth': 5, 'alpha': 15}

data_dmatrix = xgb.DMatrix(data=X_train,label=y_train)
cv_results = xgb.cv(dtrain=data_dmatrix, params=params, nfold=3,
num_boost_round=50, early_stopping_rounds=10,
metrics="rmse", as_pandas=True, seed=0)

结果看起来不错,我想用我保留的数据测试交叉验证中的最佳模型。但是我怎样才能得到模型呢?

最佳答案

不像 scikit-learn GridSearchCV ,它返回一个模型(如果使用 refit=True 调用,可以选择用整个数据重新拟合),xgb.cv 确实 not 返回任何模型,只有评估历史;来自 docs :

Returns evaluation history

在这个意义上,它类似于 scikit-learn 的 cross_validate ,它也不返回任何模型 - 仅返回指标。

因此,如果您对 CV 结果感到满意,并且希望继续使用所有数据拟合模型,则必须单独进行:

bst = xgb.train(dtrain=data_dmatrix, params=params, num_boost_round=50)

关于python - 如何从 xgboost CV 中获取经过训练的模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66681443/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com