K折交叉驗證時使用:
KFold(n_split, shuffle, random_state)
參數:n_split:要划分的折數
shuffle: 每次都進行shuffle,測試集中折數的總和就是訓練集的個數
random_state:隨機狀態
1 from sklearn.model_selection import KFold 2 kf = KFold(5, True, 10) 3 4 X, Y = loda_data('./data.txt') 5 for train_index, test_index in kf.split(X): 6 print('訓練集:{}'.format(train_index) 7 print('測試集:{}'.format(test_index)