sklearn的K折交叉驗證函數KFold使用


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)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM