使用组对预测进行嵌套交叉验证

2024-05-23 15:12:45 发布

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

我不能做一些事情,我想知道这是一个错误或正常的方式。你知道吗

我试图对数据集进行嵌套交叉验证,每个数据集都属于一个患者。为了避免在同一个病人身上学习和测试,我看到你实施了一个“群体”机制,在我的案例中,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.

在代码中,\ u fit\ u和\ u predict()方法似乎没有将组共享给估计器,因此不能使用所需的组。你知道吗

能给我一些线索吗? 祝您有个美好的一天, 致以最诚挚的问候


Tags: the数据患者search参数parameterparam交叉