gpt4 book ai didi

python - 理解 python xgboost cv

转载 作者:太空狗 更新时间:2023-10-29 17:55:22 24 4
gpt4 key购买 nike

我想使用 xgboost cv 函数为我的训练数据集找到最佳参数。我对 api 感到困惑。如何找到最佳参数?这是否类似于 sklearn grid_search 交叉验证功能?我如何找到确定 max_depth 参数 ([2,4,6]) 的哪个选项是最佳的?

from sklearn.datasets import load_iris
import xgboost as xgb
iris = load_iris()
DTrain = xgb.DMatrix(iris.data, iris.target)
x_parameters = {"max_depth":[2,4,6]}
xgb.cv(x_parameters, DTrain)
...
Out[6]:
test-rmse-mean test-rmse-std train-rmse-mean train-rmse-std
0 0.888435 0.059403 0.888052 0.022942
1 0.854170 0.053118 0.851958 0.017982
2 0.837200 0.046986 0.833532 0.015613
3 0.829001 0.041960 0.824270 0.014501
4 0.825132 0.038176 0.819654 0.013975
5 0.823357 0.035454 0.817363 0.013722
6 0.822580 0.033540 0.816229 0.013598
7 0.822265 0.032209 0.815667 0.013538
8 0.822158 0.031287 0.815390 0.013508
9 0.822140 0.030647 0.815252 0.013494

最佳答案

您可以通过 xgboost sklearn API 将 GridSearchCV 与 xgboost 一起使用

按如下方式定义分类器:

from xgboost.sklearn import XGBClassifier
from sklearn.grid_search import GridSearchCV

xgb_model = XGBClassifier(other_params)

test_params = {
'max_depth':[4,8,12]
}

model = GridSearchCV(estimator = xgb_model,param_grid = test_params)
model.fit(train,target)
print model.best_params_

关于python - 理解 python xgboost cv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34469038/

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