【发布时间】:2020-02-10 16:59:35
【问题描述】:
我无法做某事,我想知道这是错误还是正常方式。
我正在尝试对数据集进行嵌套交叉验证,每个数据集都属于一个患者。为了避免对同一患者进行学习和测试,我看到您实施了“组”机制,而 GroupKFold 在我的情况下似乎是正确的。 当我的分类器获得不同的参数时,我继续使用 GridSearchCv 来修复我的模型的超参数。同样,我认为测试/训练必须属于不同的患者。
(对于嵌套交叉验证感兴趣的人:http://scikit-learn.org/stable/auto_examples/model_selection/plot_nested_cross_validation_iris.html)
我是这样进行的:
pipe = Pipeline([('pca', PCA()),
('clf', SVC()),
])
# Find the best parameters for both the feature extraction and the classifier
grid_search = GridSearchCV(estimator=pipe, param_grid=some_param, cv=GroupKFold(n_splits=5), verbose=1)
grid_search.fit(X=features, y=labels, groups=groups)
# Nested CV with parameter optimization
predictions = cross_val_predict(grid_search, X=features, y=labels, cv=GroupKFold(n_splits=5), groups=groups)
然后得到一些:
File : _split.py", line 489, in _iter_test_indices
raise ValueError("The 'groups' parameter should not be None.")
ValueError: The 'groups' parameter should not be None.
在代码中,_fit_and_predict() 方法似乎没有将组共享给估算器,因此无法使用所需的组。
我能提供一些线索吗? 祝你今天过得愉快, 最好的问候
【问题讨论】:
标签: python scikit-learn