PredefinedSplit#
- class sklearn.model_selection.PredefinedSplit(test_fold)[源代码]#
预定义的分割交叉验证程序。
提供训练/测试索引,以使用用户指定的预定义方案将数据拆分为训练/测试集
test_fold
参数.阅读更多的 User Guide .
Added in version 0.16.
- 参数:
- test_fold形状类似阵列(n_samples,)
入境
test_fold[i]
代表该样本的测试集的索引i
属于。可以排除样本i
来自任何测试集(即包括样本i
在每个训练集中)通过设置test_fold[i]
等于-1。
示例
>>> 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()[源代码]#
获取此对象的元数据路由。
请检查 User Guide 关于路由机制如何工作。
- 返回:
- routingMetadataRequest
A
MetadataRequest
封装路由信息。