Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e87babe

Browse files
committed
Rename n_folds to n_splits
1 parent 1348e4a commit e87babe

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

sklearn/model_selection/_split.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -647,19 +647,19 @@ class HomogeneousTimeSeriesCV(_BaseKFold):
647647
648648
Parameters
649649
----------
650-
n_folds : int, default=3
651-
Number of folds. Must be at least 2.
650+
n_splits : int, default=3
651+
Number of splits. Must be at least 1.
652652
653653
Examples
654654
--------
655655
>>> from sklearn.model_selection import HomogeneousTimeSeriesCV
656656
>>> X = np.array([[1, 2], [3, 4], [1, 2], [3, 4]])
657657
>>> y = np.array([1, 2, 3, 4])
658-
>>> htscv = HomogeneousTimeSeriesCV(n_folds=4)
658+
>>> htscv = HomogeneousTimeSeriesCV(n_splits=3)
659659
>>> htscv.get_n_splits(X)
660660
3
661661
>>> print(htscv) # doctest: +NORMALIZE_WHITESPACE
662-
HomogeneousTimeSeriesCV(n_folds=4)
662+
HomogeneousTimeSeriesCV(n_splits=3)
663663
>>> for train_index, test_index in htscv.split(X):
664664
... print("TRAIN:", train_index, "TEST:", test_index)
665665
... X_train, X_test = X[train_index], X[test_index]
@@ -672,11 +672,11 @@ class HomogeneousTimeSeriesCV(_BaseKFold):
672672
-----
673673
Size of each fold here is same as size of each fold split by KFold.
674674
675-
Number of splitting iterations in this cross-validator, n_folds-1,
675+
Number of splitting iterations in this cross-validator, n_splits,
676676
is not equal to other KFold based cross-validators'.
677677
"""
678-
def __init__(self, n_folds=3):
679-
super(HomogeneousTimeSeriesCV, self).__init__(n_folds,
678+
def __init__(self, n_splits=3):
679+
super(HomogeneousTimeSeriesCV, self).__init__(n_splits,
680680
shuffle=False,
681681
random_state=None)
682682

@@ -706,12 +706,13 @@ def split(self, X, y=None, labels=None):
706706
"""
707707
X, y, labels = indexable(X, y, labels)
708708
n_samples = _num_samples(X)
709-
if self.n_folds > n_samples:
709+
n_splits = self.n_splits
710+
n_folds = n_splits + 1
711+
if n_folds > n_samples:
710712
raise ValueError(
711-
("Cannot have number of folds n_folds={0} greater"
712-
" than the number of samples: {1}.").format(self.n_folds,
713+
("Cannot have number of folds ={0} greater"
714+
" than the number of samples: {1}.").format(n_folds,
713715
n_samples))
714-
n_folds = self.n_folds
715716
indices = np.arange(n_samples)
716717
fold_sizes = (n_samples // n_folds) * np.ones(n_folds, dtype=np.int)
717718
fold_sizes[:n_samples % n_folds] += 1
@@ -741,7 +742,7 @@ def get_n_splits(self, X=None, y=None, labels=None):
741742
n_splits : int
742743
Returns the number of splitting iterations in the cross-validator.
743744
"""
744-
return self.n_folds-1
745+
return self.n_splits
745746

746747

747748
class LeaveOneLabelOut(BaseCrossValidator):

0 commit comments

Comments
 (0)