GridSearchCV的预定义拆分无法正常工作

2024-06-02 23:30:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用GridSearchCV(和BayeSearchCV)来调整我的超参数。我的训练集和验证集是预定义的,我不需要折叠。根据文档:我将训练集的索引设置为“-1”,验证集的索引设置为“0”。但是,在一个玩具示例中,GridSearchCV不能正常工作(下面是附加的程序输出)。在

from sklearn.model_selection import PredefinedSplit
# This is my training data (train+validation): X_train
# This is the corresponding y: y_train

estimator = lgb.LGBMRegressor(random_state=1000, 
objective='quantile',alpha=q*0.01)

# enforeced training set " -1"
my_test_fold = -np.ones(len(X_train), dtype=int)
# validation set "0"
my_test_fold[-100:-50]=0  

pcv = PredefinedSplit(test_fold=my_test_fold)
lgbm_cv = GridSearchCV(estimator, param_grid,cv=pcv)                        
lgbm_cv.fit(X_train, y_train)

pd.DataFrame(lgbm_cv.cv_results_)

程序输出:my_test_fold[-100:-50]=0image1

当我设置“my_test_fold[-100:-50]=0”时,cv_results_u没有“mean_test_score”。在

当我设置“my_test_fold[0:50]=0”时,cv_results_Uresults_Utest_score“的平均值”。Program output: my_test_fold[0:50]=0

在我看来,CV可能会也可能不会识别验证集,这取决于哪些数据被设置为验证?在我看来这是个虫子。有什么想法吗?在


Tags: test程序ismytrainingtrainfoldthis