@@ -188,7 +188,7 @@ def get_n_splits(self, X, y=None, groups=None):
188
188
Returns the number of splitting iterations in the cross-validator.
189
189
"""
190
190
if X is None :
191
- raise ValueError ("The X parameter should not be None" )
191
+ raise ValueError ("The 'X' parameter should not be None. " )
192
192
return _num_samples (X )
193
193
194
194
@@ -259,7 +259,7 @@ def get_n_splits(self, X, y=None, groups=None):
259
259
Always ignored, exists for compatibility.
260
260
"""
261
261
if X is None :
262
- raise ValueError ("The X parameter should not be None" )
262
+ raise ValueError ("The 'X' parameter should not be None. " )
263
263
return int (comb (_num_samples (X ), self .p , exact = True ))
264
264
265
265
@@ -477,7 +477,7 @@ def __init__(self, n_splits=3):
477
477
478
478
def _iter_test_indices (self , X , y , groups ):
479
479
if groups is None :
480
- raise ValueError ("The groups parameter should not be None" )
480
+ raise ValueError ("The ' groups' parameter should not be None. " )
481
481
groups = check_array (groups , ensure_2d = False , dtype = None )
482
482
483
483
unique_groups , groups = np .unique (groups , return_inverse = True )
@@ -765,6 +765,8 @@ class LeaveOneGroupOut(BaseCrossValidator):
765
765
>>> logo = LeaveOneGroupOut()
766
766
>>> logo.get_n_splits(X, y, groups)
767
767
2
768
+ >>> logo.get_n_splits(groups=groups) # 'groups' is always required
769
+ 2
768
770
>>> print(logo)
769
771
LeaveOneGroupOut()
770
772
>>> for train_index, test_index in logo.split(X, y, groups):
@@ -785,7 +787,7 @@ class LeaveOneGroupOut(BaseCrossValidator):
785
787
786
788
def _iter_test_masks (self , X , y , groups ):
787
789
if groups is None :
788
- raise ValueError ("The groups parameter should not be None" )
790
+ raise ValueError ("The ' groups' parameter should not be None. " )
789
791
# We make a copy of groups to avoid side-effects during iteration
790
792
groups = check_array (groups , copy = True , ensure_2d = False , dtype = None )
791
793
unique_groups = np .unique (groups )
@@ -796,28 +798,31 @@ def _iter_test_masks(self, X, y, groups):
796
798
for i in unique_groups :
797
799
yield groups == i
798
800
799
- def get_n_splits (self , X , y , groups ):
801
+ def get_n_splits (self , X = None , y = None , groups = None ):
800
802
"""Returns the number of splitting iterations in the cross-validator
801
803
802
804
Parameters
803
805
----------
804
- X : object
806
+ X : object, optional
805
807
Always ignored, exists for compatibility.
806
808
807
- y : object
809
+ y : object, optional
808
810
Always ignored, exists for compatibility.
809
811
810
812
groups : array-like, with shape (n_samples,), optional
811
813
Group labels for the samples used while splitting the dataset into
812
- train/test set.
814
+ train/test set. This 'groups' parameter must always be specified to
815
+ calculate the number of splits, though the other parameters can be
816
+ omitted.
813
817
814
818
Returns
815
819
-------
816
820
n_splits : int
817
821
Returns the number of splitting iterations in the cross-validator.
818
822
"""
819
823
if groups is None :
820
- raise ValueError ("The groups parameter should not be None" )
824
+ raise ValueError ("The 'groups' parameter should not be None." )
825
+ groups = check_array (groups , ensure_2d = False , dtype = None )
821
826
return len (np .unique (groups ))
822
827
823
828
@@ -852,6 +857,8 @@ class LeavePGroupsOut(BaseCrossValidator):
852
857
>>> lpgo = LeavePGroupsOut(n_groups=2)
853
858
>>> lpgo.get_n_splits(X, y, groups)
854
859
3
860
+ >>> lpgo.get_n_splits(groups=groups) # 'groups' is always required
861
+ 3
855
862
>>> print(lpgo)
856
863
LeavePGroupsOut(n_groups=2)
857
864
>>> for train_index, test_index in lpgo.split(X, y, groups):
@@ -879,7 +886,7 @@ def __init__(self, n_groups):
879
886
880
887
def _iter_test_masks (self , X , y , groups ):
881
888
if groups is None :
882
- raise ValueError ("The groups parameter should not be None" )
889
+ raise ValueError ("The ' groups' parameter should not be None. " )
883
890
groups = check_array (groups , copy = True , ensure_2d = False , dtype = None )
884
891
unique_groups = np .unique (groups )
885
892
if self .n_groups >= len (unique_groups ):
@@ -895,32 +902,31 @@ def _iter_test_masks(self, X, y, groups):
895
902
test_index [groups == l ] = True
896
903
yield test_index
897
904
898
- def get_n_splits (self , X , y , groups ):
905
+ def get_n_splits (self , X = None , y = None , groups = None ):
899
906
"""Returns the number of splitting iterations in the cross-validator
900
907
901
908
Parameters
902
909
----------
903
- X : object
910
+ X : object, optional
904
911
Always ignored, exists for compatibility.
905
- ``np.zeros(n_samples)`` may be used as a placeholder.
906
912
907
- y : object
913
+ y : object, optional
908
914
Always ignored, exists for compatibility.
909
- ``np.zeros(n_samples)`` may be used as a placeholder.
910
915
911
916
groups : array-like, with shape (n_samples,), optional
912
917
Group labels for the samples used while splitting the dataset into
913
- train/test set.
918
+ train/test set. This 'groups' parameter must always be specified to
919
+ calculate the number of splits, though the other parameters can be
920
+ omitted.
914
921
915
922
Returns
916
923
-------
917
924
n_splits : int
918
925
Returns the number of splitting iterations in the cross-validator.
919
926
"""
920
927
if groups is None :
921
- raise ValueError ("The groups parameter should not be None" )
928
+ raise ValueError ("The ' groups' parameter should not be None. " )
922
929
groups = check_array (groups , ensure_2d = False , dtype = None )
923
- X , y , groups = indexable (X , y , groups )
924
930
return int (comb (len (np .unique (groups )), self .n_groups , exact = True ))
925
931
926
932
@@ -1318,7 +1324,7 @@ def __init__(self, n_splits=5, test_size=0.2, train_size=None,
1318
1324
1319
1325
def _iter_indices (self , X , y , groups ):
1320
1326
if groups is None :
1321
- raise ValueError ("The groups parameter should not be None" )
1327
+ raise ValueError ("The ' groups' parameter should not be None. " )
1322
1328
groups = check_array (groups , ensure_2d = False , dtype = None )
1323
1329
classes , group_indices = np .unique (groups , return_inverse = True )
1324
1330
for group_train , group_test in super (
0 commit comments