Python机器学习库sklearn KFold交叉验证分组情况样本

时间:2021-11-11 15:09:28

sklearn官网KFold交叉验证
http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.KFold.html#sklearn.model_selection.KFold

from sklearn.cross_validation import KFold
fold = KFold(50,5,shuffle=False)
for iteration, indices in enumerate(fold,start=1):
    print(iteration, indices)

Python机器学习库sklearn KFold交叉验证分组情况样本

注意看indices的输出的是两个关于样本索引号的array,前一个用于训练,后一个用于验证。