PredefinedSplit#
- class sklearn.model_selection.PredefinedSplit(test_fold)[源]#
预定义分割交叉验证器。
使用用户通过
test_fold
参数指定的预定义方案,提供训练/测试索引以将数据分割为训练/测试集。在用户指南中阅读更多信息。
版本 0.16 中新增。
- 参数:
- test_foldarray-like of shape (n_samples,)
test_fold[i]
条目表示样本i
所属的测试集的索引。通过将test_fold[i]
设置为 -1,可以将样本i
从任何测试集中排除(即,将样本i
包含在每个训练集中)。
示例
>>> import numpy as np >>> from sklearn.model_selection import PredefinedSplit >>> X = np.array([[1, 2], [3, 4], [1, 2], [3, 4]]) >>> y = np.array([0, 0, 1, 1]) >>> test_fold = [0, 1, -1, 1] >>> ps = PredefinedSplit(test_fold) >>> ps.get_n_splits() 2 >>> print(ps) PredefinedSplit(test_fold=array([ 0, 1, -1, 1])) >>> for i, (train_index, test_index) in enumerate(ps.split()): ... print(f"Fold {i}:") ... print(f" Train: index={train_index}") ... print(f" Test: index={test_index}") Fold 0: Train: index=[1 2 3] Test: index=[0] Fold 1: Train: index=[0 2] Test: index=[1 3]
- get_metadata_routing()[源]#
获取此对象的元数据路由。
请查阅用户指南了解路由机制的工作原理。
- 返回:
- routingMetadataRequest
一个封装路由信息的
MetadataRequest
对象。