預定義分割#
- class sklearn.model_selection.PredefinedSplit(test_fold)[原始碼]#
預定義分割交叉驗證器。
使用
test_fold
參數,提供訓練/測試索引,以使用使用者指定的預定義方案將資料分割成訓練/測試集。請參閱使用者指南以了解更多資訊。
在版本 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()[原始碼]#
取得此物件的中繼資料路由。
請查看 使用者指南,了解路由機制的運作方式。
- 回傳值:
- routingMetadataRequest
封裝路由資訊的
MetadataRequest
。