我试图在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()缺少1个必需的位置参数:“param_grid”
看起来你把
tuned_parameters
:D放错地方了;请尝试将clf
定义作为让我知道这是否有效
相关问题 更多 >
编程相关推荐