param_grid 使用 Xgboost 进行调优时出错
param_grid error when using Xgboost for tuning
我正在尝试为 XG Boost 模型编写超参数调整代码。但是,我不断收到错误消息。这是代码:
#define X,y
y = data.SalePrice
x = data.drop(['SalePrice'], axis=1).select_dtypes(exclude=['object'])
#test,train split
train_x, test_x, train_y, test_y = train_test_split(x, y, test_size=0.3, random_state=0)
#Imputation transformer for completing missing values.
my_imputer = Imputer()
#Seperate train and test X
train_x = my_imputer.fit_transform(train_x)
test_x = my_imputer.transform(test_x)
那么,这里是数据的超参数:
# Set the parameters by cross-validation
tuned_parameters = [{'n_estimators': [5, 25, 50, 100, 250, 500],'learning_rate': [0.01,0.05]}]
scores = ['precision', 'recall']
for score in scores:
print("# Tuning hyper-parameters for %s" % score)
print()
#XGBRegressor
clf = GridSearchCV(XGBRegressor(tuned_parameters), cv=5,scoring='%s_macro' % score)
clf.fit(train_x, train_y)
print("Best parameters set found on development set:")
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)
让我知道是否有效。
我正在尝试为 XG Boost 模型编写超参数调整代码。但是,我不断收到错误消息。这是代码:
#define X,y
y = data.SalePrice
x = data.drop(['SalePrice'], axis=1).select_dtypes(exclude=['object'])
#test,train split
train_x, test_x, train_y, test_y = train_test_split(x, y, test_size=0.3, random_state=0)
#Imputation transformer for completing missing values.
my_imputer = Imputer()
#Seperate train and test X
train_x = my_imputer.fit_transform(train_x)
test_x = my_imputer.transform(test_x)
那么,这里是数据的超参数:
# Set the parameters by cross-validation
tuned_parameters = [{'n_estimators': [5, 25, 50, 100, 250, 500],'learning_rate': [0.01,0.05]}]
scores = ['precision', 'recall']
for score in scores:
print("# Tuning hyper-parameters for %s" % score)
print()
#XGBRegressor
clf = GridSearchCV(XGBRegressor(tuned_parameters), cv=5,scoring='%s_macro' % score)
clf.fit(train_x, train_y)
print("Best parameters set found on development set:")
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)
让我知道是否有效。