RepeatedKFold#
- class sklearn.model_selection.RepeatedKFold(*, n_splits=5, n_repeats=10, random_state=None)[source]#
重复K折交叉验证器。
在每次重复中,将K折交叉验证重复
n_repeats
次,每次使用不同的随机化。详情请参阅用户指南。
- 参数:
- n_splits整型, 默认值=5
折叠数。必须至少为2。
- n_repeats整型, 默认值=10
交叉验证器需要重复的次数。
- random_state整型, RandomState 实例或 None, 默认值=None
控制每个重复交叉验证实例的随机性。传入一个整型值以在多次函数调用中获得可重现的输出。请参阅术语表。
另请参阅
RepeatedStratifiedKFold
重复分层K折交叉验证n次。
备注
随机化的交叉验证(CV)分割器每次调用 `split` 可能会返回不同的结果。通过将
random_state
设置为整数,可以使结果相同。示例
>>> import numpy as np >>> from sklearn.model_selection import RepeatedKFold >>> X = np.array([[1, 2], [3, 4], [1, 2], [3, 4]]) >>> y = np.array([0, 0, 1, 1]) >>> rkf = RepeatedKFold(n_splits=2, n_repeats=2, random_state=2652124) >>> rkf.get_n_splits(X, y) 4 >>> print(rkf) RepeatedKFold(n_repeats=2, n_splits=2, random_state=2652124) >>> for i, (train_index, test_index) in enumerate(rkf.split(X)): ... print(f"Fold {i}:") ... print(f" Train: index={train_index}") ... print(f" Test: index={test_index}") ... Fold 0: Train: index=[0 1] Test: index=[2 3] Fold 1: Train: index=[2 3] Test: index=[0 1] Fold 2: Train: index=[1 2] Test: index=[0 3] Fold 3: Train: index=[0 3] Test: index=[1 2]
- get_metadata_routing()[source]#
获取此对象的元数据路由。
请查看用户指南以了解路由机制的工作原理。
- 返回:
- routingMetadataRequest
一个封装了路由信息的
MetadataRequest
。