forked from scikit-learn/scikit-learn
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MRG + 2] FIX Be robust to non re-entrant/ non deterministic cv.split…
… calls (scikit-learn#7660)
- Loading branch information
1 parent
0a75abc
commit 8d731ee
Showing
7 changed files
with
226 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
""" | ||
Common utilities for testing model selection. | ||
""" | ||
|
||
import numpy as np | ||
|
||
from sklearn.model_selection import KFold | ||
|
||
|
||
class OneTimeSplitter: | ||
"""A wrapper to make KFold single entry cv iterator""" | ||
def __init__(self, n_splits=4, n_samples=99): | ||
self.n_splits = n_splits | ||
self.n_samples = n_samples | ||
self.indices = iter(KFold(n_splits=n_splits).split(np.ones(n_samples))) | ||
|
||
def split(self, X=None, y=None, groups=None): | ||
"""Split can be called only once""" | ||
for index in self.indices: | ||
yield index | ||
|
||
def get_n_splits(self, X=None, y=None, groups=None): | ||
return self.n_splits |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.