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

Skip to content

Commit 2b1c31e

Browse files
mjbommaramueller
authored andcommitted
Adding unit test to cover ties/duplicate x values in Isotonic Regression re: issue scikit-learn#4184
Expanding tests to include ties at both x_min and x_max Updating unit test to include reference data against R's isotone gpava() with ties=primary Adding R and isotone package versions for reproducibility/documentation Removing double space in docstring Combining tests for fit and transform with ties; fixing spelling error
1 parent 6ce0b35 commit 2b1c31e

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

sklearn/tests/test_isotonic.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,60 @@ def test_isotonic_regression():
8181
assert_array_equal(ir.fit_transform(np.ones(len(x)), y), y)
8282

8383

84+
def test_isotonic_regression_ties_min():
85+
# Setup examples with ties on minimum
86+
x = [0, 1, 1, 2, 3, 4, 5]
87+
y = [0, 1, 2, 3, 4, 5, 6]
88+
89+
# Check that we get identical results for fit/transform and fit_transform
90+
ir = IsotonicRegression()
91+
ir.fit(x, y)
92+
assert_array_equal(ir.fit(x, y).transform(x), ir.fit_transform(x, y))
93+
94+
95+
def test_isotonic_regression_ties_max():
96+
# Setup examples with ties on maximum
97+
x = [1, 2, 3, 4, 5, 5]
98+
y = [1, 2, 3, 4, 5, 6]
99+
100+
# Check that we get identical results for fit/transform and fit_transform
101+
ir = IsotonicRegression()
102+
ir.fit(x, y)
103+
assert_array_equal(ir.fit(x, y).transform(x), ir.fit_transform(x, y))
104+
105+
106+
def test_isotonic_regression_ties_primary_():
107+
"""
108+
Test isotonic regression fit, transform and fit_transform
109+
against the "primary" ties method and "pituitary" data from R
110+
"isotone" package, as detailed in: J. d. Leeuw, K. Hornik, P. Mair,
111+
Isotone Optimization in R: Pool-Adjacent-Violators Algorithm
112+
(PAVA) and Active Set Methods
113+
"""
114+
115+
"""
116+
Set values based on pituitary example and
117+
the following R command detailed in the paper above:
118+
> library("isotone")
119+
> data("pituitary")
120+
> res1 <- gpava(pituitary$age, pituitary$size, ties="primary")
121+
> res1$x
122+
123+
`isotone` version: 1.0-2, 2014-09-07
124+
R version: R version 3.1.1 (2014-07-10)
125+
"""
126+
x = [8, 8, 8, 10, 10, 10, 12, 12, 12, 14, 14]
127+
y = [21, 23.5, 23, 24, 21, 25, 21.5, 22, 19, 23.5, 25]
128+
y_true = [21, 22.375, 22.375, 22.375, 22.375, 22.375, 22.375,
129+
22.375, 22.375, 23.5, 25]
130+
131+
# Check fit, transform and fit_transform
132+
ir = IsotonicRegression()
133+
ir.fit(x, y)
134+
assert_array_equal(ir.transform(x), y_true)
135+
assert_array_equal(ir.fit_transform(x, y), y_true)
136+
137+
84138
def test_isotonic_regression_reversed():
85139
y = np.array([10, 9, 10, 7, 6, 6.1, 5])
86140
y_ = IsotonicRegression(increasing=False).fit_transform(

0 commit comments

Comments
 (0)