close
之前為了將資料分五群而思考程式該如何達成
簡單的作法是直接將每一筆資料依序丟到五個袋子中的一個
但是這樣的作法太粗糙
所以趕緊來使用專屬套件來完成這件事情
# 首先 import 所需要的套件名稱
from sklearn.model_selection import KFold
import numpy as np
# 設定資料集
X = np.arange(24).reshape(12,2)
y = np.random.choice([1,2],12,p=[0.4,0.6])
# 設定今天的主角,n_splits=5 代表分五等分,shuffle=True 能讓每一次都分出不同的五份
kf = KFold(n_splits=5,shuffle=True)
# 針對分好的五等分,列印相對應的資料
for train_index , test_index in kf.split(X):
print('train_index:%s , test_index: %s ' %(train_index,test_index))
文章標籤
全站熱搜