Python:手寫10折交叉驗證 分離數據集爲training set 和 testing set 的步驟

import numpy as np

n = 23
CV = 10
testNum = int(np.floor(n / CV))
tempCake = [i for i in range(n)]
for i in range(CV):
    wholeCake = np.array([i for i in range(n)])
    testIndices = np.random.choice(tempCake, size=testNum, replace=False)
    trainIndices = np.delete(wholeCake, testIndices)
    for ele in testIndices:
        tempCake.remove(ele)
    print(testIndices,trainIndices,tempCake)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章