@@ -271,7 +271,7 @@ class _BaseKFold(with_metaclass(ABCMeta, BaseCrossValidator)):
271
271
272
272
@abstractmethod
273
273
def __init__ (self , n_splits , shuffle , random_state ):
274
- if not isinstance (n_splits , numbers .Integral ):
274
+ if not isinstance (n_splits , ( numbers .Integral , np . integer ) ):
275
275
raise ValueError ('The number of folds must be of Integral type. '
276
276
'%s of type %s was passed.'
277
277
% (n_splits , type (n_splits )))
@@ -1643,27 +1643,27 @@ def _validate_shuffle_split_init(test_size, train_size):
1643
1643
raise ValueError ('test_size and train_size can not both be None' )
1644
1644
1645
1645
if test_size is not None :
1646
- if np . asarray (test_size ). dtype . kind == 'f' :
1646
+ if isinstance (test_size , ( float , np . floating )) :
1647
1647
if test_size >= 1. :
1648
1648
raise ValueError (
1649
1649
'test_size=%f should be smaller '
1650
1650
'than 1.0 or be an integer' % test_size )
1651
- elif np . asarray (test_size ). dtype . kind != 'i' :
1651
+ elif not isinstance (test_size , ( numbers . Integral , np . integer )) :
1652
1652
# int values are checked during split based on the input
1653
1653
raise ValueError ("Invalid value for test_size: %r" % test_size )
1654
1654
1655
1655
if train_size is not None :
1656
- if np . asarray (train_size ). dtype . kind == 'f' :
1656
+ if isinstance (train_size , ( float , np . floating )) :
1657
1657
if train_size >= 1. :
1658
1658
raise ValueError ("train_size=%f should be smaller "
1659
1659
"than 1.0 or be an integer" % train_size )
1660
- elif (np . asarray (test_size ). dtype . kind == 'f' and
1660
+ elif (isinstance (test_size , ( float , np . floating )) and
1661
1661
(train_size + test_size ) > 1. ):
1662
1662
raise ValueError ('The sum of test_size and train_size = %f, '
1663
1663
'should be smaller than 1.0. Reduce '
1664
1664
'test_size and/or train_size.' %
1665
1665
(train_size + test_size ))
1666
- elif np . asarray (train_size ). dtype . kind != 'i' :
1666
+ elif not isinstance (train_size , ( numbers . Integral , np . integer )) :
1667
1667
# int values are checked during split based on the input
1668
1668
raise ValueError ("Invalid value for train_size: %r" % train_size )
1669
1669
@@ -1672,30 +1672,32 @@ def _validate_shuffle_split(n_samples, test_size, train_size):
1672
1672
"""
1673
1673
Validation helper to check if the test/test sizes are meaningful wrt to the
1674
1674
size of the data (n_samples)
1675
+
1676
+ test_size, defaults
8000
to 0.1
1675
1677
"""
1676
1678
if (test_size is not None and
1677
- np . asarray (test_size ). dtype . kind == 'i' and
1679
+ isinstance (test_size , ( numbers . Integral , np . integer )) and
1678
1680
test_size >= n_samples ):
1679
1681
raise ValueError ('test_size=%d should be smaller than the number of '
1680
1682
'samples %d' % (test_size , n_samples ))
1681
1683
1682
1684
if (train_size is not None and
1683
- np . asarray (train_size ). dtype . kind == 'i' and
1685
+ isinstance (train_size , ( numbers . Integral , np . integer )) and
1684
1686
train_size >= n_samples ):
1685
1687
raise ValueError ("train_size=%d should be smaller than the number of"
1686
1688
" samples %d" % (train_size , n_samples ))
1687
1689
1688
1690
if test_size == "default" :
1689
1691
test_size = 0.1
1690
1692
1691
- if np . asarray (test_size ). dtype . kind == 'f' :
1693
+ if isinstance (test_size , ( float , np . floating )) :
1692
1694
n_test = ceil (test_size * n_samples )
1693
- elif np . asarray (test_size ). dtype . kind == 'i' :
1695
+ elif isinstance (test_size , ( numbers . Integral , np . integer )) :
1694
1696
n_test = float (test_size )
1695
1697
1696
1698
if train_size is None :
1697
1699
n_train = n_samples - n_test
1698
- elif np . asarray (train_size ). dtype . kind == 'f' :
1700
+ elif isinstance (train_size , ( float , np . floating )) :
1699
1701
n_train = floor (train_size * n_samples )
1700
1702
else :
1701
1703
n_train = float (train_size )
@@ -1900,7 +1902,7 @@ def check_cv(cv=3, y=None, classifier=False):
1900
1902
if cv is None :
1901
1903
cv = 3
1902
1904
1903
- if isinstance (cv , numbers .Integral ):
1905
+ if isinstance (cv , ( numbers .Integral , np . integer ) ):
1904
1906
if (classifier and (y is not None ) and
1905
1907
(type_of_target (y ) in ('binary' , 'multiclass' ))):
1906
1908
return StratifiedKFold (cv )
0 commit comments