-
-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Adding unit test to cover ties/duplicate x values in Isotonic Regression... #4185
Closed
mjbommar
wants to merge
7
commits into
scikit-learn:master
from
mjbommar:issue-4184-isotonic-x-tie-unit-test
Closed
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a70094d
Adding unit test to cover ties/duplicate x values in Isotonic Regress…
mjbommar 8b0c0da
Expanding tests to include ties at both x_min and x_max
mjbommar de7d6bf
Updating unit test to include reference data against R's isotone gpav…
mjbommar 3dcbae7
Adding R and isotone package versions for reproducibility/documentation
mjbommar c31e8b3
Removing double space in docstring
mjbommar 814a49e
Combining tests for fit and transform with ties; fixing spelling error
mjbommar 13a4ffb
Merge branch 'master' into issue-4184-isotonic-x-tie-unit-test
mjbommar File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,89 @@ def test_isotonic_regression(): | |
assert_array_equal(ir.fit_transform(np.ones(len(x)), y), y) | ||
|
||
|
||
def test_isotonic_regression_ties_min(): | ||
# Setup examples with ties on minimum | ||
x = [0, 1, 1, 2, 3, 4, 5] | ||
y = [0, 1, 2, 3, 4, 5, 6] | ||
|
||
# Check that we get identical results for fit/transform and fit_transform | ||
ir = IsotonicRegression() | ||
ir.fit(x, y) | ||
assert_array_equal(ir.fit(x, y).transform(x), ir.fit_transform(x, y)) | ||
|
||
|
||
def test_isotonic_regression_ties_max(): | ||
# Setup examples with ties on maximum | ||
x = [1, 2, 3, 4, 5, 5] | ||
y = [1, 2, 3, 4, 5, 6] | ||
|
||
# Check that we get identical results for fit/transform and fit_transform | ||
ir = IsotonicRegression() | ||
ir.fit(x, y) | ||
assert_array_equal(ir.fit(x, y).transform(x), ir.fit_transform(x, y)) | ||
|
||
|
||
def test_isotonic_regression_ties_primary_fit(): | ||
""" | ||
Test isotonic regression fit, transform against the "primary" ties method | ||
and "pituitary" data from R "isotone" package, as detailed in | ||
J. d. Leeuw, K. Hornik, P. Mair, | ||
Isotone Optimization in R: Pool-Adjacent-Violators Algorithm | ||
(PAVA) and Active Set Methods | ||
""" | ||
|
||
""" | ||
Set values based on pituitiary example and | ||
the following R command detailed in the paper above: | ||
> library("isotone") | ||
> data("pituitary") | ||
> res1 <- gpava(pituitary$age, pituitary$size, ties="primary") | ||
> res1$x | ||
|
||
`isotone` version: 1.0-2, 2014-09-07 | ||
R version: R version 3.1.1 (2014-07-10) | ||
""" | ||
x = [8, 8, 8, 10, 10, 10, 12, 12, 12, 14, 14] | ||
y = [21, 23.5, 23, 24, 21, 25, 21.5, 22, 19, 23.5, 25] | ||
y_true = [21, 22.375, 22.375, 22.375, 22.375, 22.375, 22.375, | ||
22.375, 22.375, 23.5, 25] | ||
|
||
# Check fit, transform | ||
ir = IsotonicRegression() | ||
ir.fit(x, y) | ||
assert_array_equal(ir.transform(x), y_true) | ||
|
||
|
||
def test_isotonic_regression_ties_primary_fit_transform(): | ||
""" | ||
Test isotonic regression fit_transform against the "primary" ties method | ||
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. 2 spaces after transform but besides LGTM if travis is happy :) thanks @mjbommar 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. oops, fixed now, thanks. travis was happy other than these 3 failures:
|
||
and "pituitary" data from R "isotone" package, as detailed in | ||
J. d. Leeuw, K. Hornik, P. Mair, | ||
Isotone Optimization in R: Pool-Adjacent-Violators Algorithm | ||
(PAVA) and Active Set Methods | ||
""" | ||
|
||
""" | ||
Set values based on pituitiary example and | ||
the following R command detailed in the paper above: | ||
> library("isotone") | ||
> data("pituitary") | ||
> res1 <- gpava(pituitary$age, pituitary$size, ties="primary") | ||
> res1$x | ||
|
||
`isotone` version: 1.0-2, 2014-09-07 | ||
R version: R version 3.1.1 (2014-07-10) | ||
""" | ||
x = [8, 8, 8, 10, 10, 10, 12, 12, 12, 14, 14] | ||
y = [21, 23.5, 23, 24, 21, 25, 21.5, 22, 19, 23.5, 25] | ||
y_true = [21, 22.375, 22.375, 22.375, 22.375, 22.375, 22.375, | ||
22.375, 22.375, 23.5, 25] | ||
|
||
# Check fit_transform against y_true | ||
ir = IsotonicRegression() | ||
assert_array_equal(ir.fit_transform(x, y), y_true) | ||
|
||
|
||
def test_isotonic_regression_reversed(): | ||
y = np.array([10, 9, 10, 7, 6, 6.1, 5]) | ||
y_ = IsotonicRegression(increasing=False).fit_transform( | ||
|
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.
I would put the two in the same test, I think.
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.
Done!