原理介绍
K折交叉验证:
KFold,GroupKFold,StratifiedKFold,
留一法:
LeaveOneGroupOut,LeavePGroupsOut,LeaveOneOut,LeavePOut,
随机划分法:
ShuffleSplit,GroupShuffleSplit,StratifiedShuffleSplit,
代码实现
流程:
实例化分类器 -> 迭代器迭代组[.split()]
KFold(n_splits=2)
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
GroupKFold(n_splits=2)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
StratifiedKFold(n_splits=3)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
LeaveOneOut()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
LeavePOut(p=3)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
ShuffleSplit(n_splits=3,test_size=.25,random_state=0)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
StratifiedShuffleSplit(n_splits=3,test_size=.5,random_state=0)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|