python - Performing grid search with a predefined validation set Sklearn -
this question has been asked several times before. error when following answer
first specify part training set , validation set follows.
my_test_fold = [] in range(len(train_x)): my_test_fold.append(-1) in range(len(test_x)): my_test_fold.append(0)
and gridsearch performed.
from sklearn.model_selection import predefinedsplit param = { 'n_estimators':[200], 'max_depth':[5], 'min_child_weight':[3], 'reg_alpha':[6], 'gamma':[0.6], 'scale_neg_weight':[1], 'learning_rate':[0.09] } gsearch1 = gridsearchcv(estimator = xgbclassifier( objective= 'reg:linear', seed=1), param_grid = param, scoring='roc_auc', cv = predefinedsplit(test_fold=my_test_fold), verbose = 1) gsearch1.fit(new_data_df, df_y)
but following error
object of type 'predefinedsplit' has no len()
try replace
cv = predefinedsplit(test_fold=my_test_fold)
with
cv = list(predefinedsplit(test_fold=my_test_fold).split(new_data_df, df_y))
the reason may need apply split method split training , testing (and transform iterable object list object).
Comments
Post a Comment