我对sklearn中的GridSearchCV
有以下问题。我尝试过,但是找不到明确的答案。以下是使用-
dep = df2['responder_flag']
indep = df2.drop(df2.columns[[0,85]], axis = 1)
X_train, X_test, y_train, y_test = train_test_split(indep, dep,test_size=0.25, random_state = 23)
train = xgb.XGBClassifier(objective='binary:logistic')
param_grid = {'max_depth': [4,5], 'n_estimators': [500], 'learning_rate': [0.02,0.01]}
grid = GridSearchCV(train, param_grid,cv=5, scoring='roc_auc')
grid.fit(X_train, y_train)
cross_validation
,即GridSearchCV
中的cv参数是否等效于Kfold
或在训练数据时使用cross_validation_score
和其他类似功能明确应用的其他CV技术?GridsearchCV
进行交叉验证吗?说如果我不提供多个参数列表,它将等于交叉验证技术吗?grid.fit(X_train, y_train)
语句,是否在确定的最佳参数上训练模型,并且可以直接用于模型预测,还是需要用grid.best_params_
定义另一个估计器,然后训练并将其用于预测?如果早点回答,对不起。
cv
参数等于k倍。在GridSearchCV
中,我们给出了我们希望模型采用的一组参数值。假设我们从[0.0001,0.001,0.01,0.1,1,10]中取learning_rate
= 0.0001。当我们在gridsearch
中指定cv = 5时,它将对5-fold cv
执行000.1
。同样,它将对其余值执行5-fold cv
。在这种情况下,k为5。GridSearchCV
是用于执行超参数调整的方法。如果未指定多个参数列表,则将无法使用GridSearch。 grid.best_params_
之后,无需在训练集上用grid.fit(X_train, y_train)
手动拟合模型。 GridSearchv
有一个名为“ refitwhich will refit the
grid.best_esitmator_to the whole training set automatically if we set
refit = True. It is by default set to
True”的参数。 Documentation