-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[MRG + 2] ShuffleLabelsOut cross-validation iterator #4583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
693f425
Merge pull request #1 from scikit-learn/master
bmcfee ebfea02
added ShuffleLabelsOut cv iterator
bmcfee 36c9c3d
fixed tests for shufflelabelsout
bmcfee 3493ec7
updated docstring
bmcfee 62e1996
Fixed an error in call to the super constructor
bmcfee ba7f81e
fixed repr, variable names in ShuffleLabelsOut
bmcfee a0a2764
added length and repr tests to ShuffleLabelsOut
bmcfee 0030d32
added documentation for ShuffleLabelsOut
bmcfee 0845929
Merge branch 'master' of github.com:bmcfee/scikit-learn
bmcfee 5c4bbcd
Merge branch 'master' of github.com:scikit-learn/scikit-learn
bmcfee 13c15fc
updated ShuffleLabelsOut in whats_new
bmcfee 5669892
ShuffleLabelsOut updated docstring for double-backtick
bmcfee 2db0196
Merge branch 'master' of github.com:scikit-learn/scikit-learn
bmcfee f0c4a75
added ShuffleLabelsOut cv iterator
bmcfee d668f3b
fixed tests for shufflelabelsout
bmcfee 068cb38
updated docstring
bmcfee 74c2657
Fixed an error in call to the super constructor
bmcfee 41d3704
fixed repr, variable names in ShuffleLabelsOut
bmcfee 085f381
added length and repr tests to ShuffleLabelsOut
bmcfee 915144a
added documentation for ShuffleLabelsOut
bmcfee e2a5ad7
updated ShuffleLabelsOut in whats_new
bmcfee e2b2a6e
ShuffleLabelsOut updated docstring for double-backtick
bmcfee 0c6f595
rebasing to master
bmcfee ab74b1d
renamed ShuffleLabelsOut to LabelShuffleSplit
bmcfee 99c66f0
LabelShuffleSplit test checks for proper ratios
bmcfee 98906df
LabelShuffleSplit documentation header fix
bmcfee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -483,6 +483,45 @@ def test_predefinedsplit_with_kfold_split(): | |
assert_array_equal(ps_test, kf_test) | ||
|
||
|
||
def test_label_shuffle_split(): | ||
ys = [np.array([1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3]), | ||
np.array([0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3]), | ||
np.array([0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2]), | ||
np.array([1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4]), | ||
] | ||
|
||
for y in ys: | ||
n_iter = 6 | ||
test_size = 1./3 | ||
slo = cval.LabelShuffleSplit(y, n_iter, test_size=test_size, | ||
random_state=0) | ||
|
||
# Make sure the repr works | ||
repr(slo) | ||
|
||
# Test that the length is correct | ||
assert_equal(len(slo), n_iter) | ||
|
||
y_unique = np.unique(y) | ||
|
||
for train, test in slo: | ||
# First test: no train label is in the test set and vice versa | ||
y_train_unique = np.unique(y[train]) | ||
y_test_unique = np.unique(y[test]) | ||
assert_false(np.any(np.in1d(y[train], y_test_unique))) | ||
assert_false(np.any(np.in1d(y[test], y_train_unique))) | ||
|
||
# Second test: train and test add up to all the data | ||
assert_equal(y[train].size + y[test].size, y.size) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
# Third test: train and test are disjoint | ||
assert_array_equal(np.lib.arraysetops.intersect1d(train, test), []) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just |
||
|
||
# Fourth test: # unique train and test labels are correct, +- 1 for rounding error | ||
assert_true(abs(len(y_test_unique) - round(test_size * len(y_unique))) <= 1) | ||
assert_true(abs(len(y_train_unique) - round((1.0 - test_size) * len(y_unique))) <= 1) | ||
|
||
|
||
def test_leave_label_out_changing_labels(): | ||
# Check that LeaveOneLabelOut and LeavePLabelOut work normally if | ||
# the labels variable is changed before calling __iter__ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At some point this should be in a common test for all cross-validation generators, but this is not the place.