使用Xgboost进行调参时的param_grid错误

我正在尝试为XG Boost模型编写超参数调优代码。然而,我不断遇到一个错误。以下是我的代码:

#定义X,y
y = data.SalePrice
x = data.drop(['SalePrice'], axis=1).select_dtypes(exclude=['object'])
#测试集和训练集的分割
train_x, test_x, train_y, test_y = train_test_split(x, y, test_size=0.3, random_state=0)
#用于填补缺失值的插补变换器
my_imputer = Imputer()
#分别处理训练和测试集的X
train_x = my_imputer.fit_transform(train_x)
test_x = my_imputer.transform(test_x)

然后,这是数据的超参数设置:

#通过交叉验证设置参数
tuned_parameters = [{'n_estimators': [5, 25, 50, 100, 250, 500],'learning_rate': [0.01,0.05]}]
scores = ['precision', 'recall']
for score in scores:
    print("# 针对%s进行超参数调优" % score)
    print()
    #XGBRegressor
    clf = GridSearchCV(XGBRegressor(tuned_parameters), cv=5,scoring='%s_macro' % score)
    clf.fit(train_x, train_y)
    print("在开发集上找到的最佳参数设置:")
    print(clf.best_params_)

我遇到的错误是:TypeError: __init__() missing 1 required positional argument: ‘param_grid’


回答:

看起来你的tuned_parameters放错了位置:D;尝试重新定义clf如下:

clf = GridSearchCV(XGBRegressor(), param_grid=tuned_parameters, cv=5,scoring='%s_macro' % score)

然后告诉我是否有效。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注