Skip to content

Commit 85c0b45

Browse files
committed
Merge pull request scikit-learn#1504 from NelleV/isotonic
ENH isotonic regression is now slighty more robust to noise
2 parents 9364e39 + a716b3c commit 85c0b45

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Diff for: sklearn/isotonic.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,8 @@ def fit_transform(self, X, y, weight=None):
227227
X, y, weight = check_arrays(X, y, weight, sparse_format='dense')
228228
y = as_float_array(y)
229229
self._check_fit_data(X, y, weight)
230-
order = np.argsort(X)
231-
order_inv = np.zeros(len(y), dtype=np.int)
232-
order_inv[order] = np.arange(len(y))
230+
order = np.lexsort((y, X))
231+
order_inv = np.argsort(order)
233232
self.X_ = as_float_array(X[order], copy=False)
234233
self.y_ = isotonic_regression(y[order], weight, self.y_min, self.y_max)
235234
return self.y_[order_inv]

Diff for: sklearn/tests/test_isotonic.py

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ def test_isotonic_regression():
2424
ir.fit_transform(x, y)[perm])
2525
assert_array_equal(ir.transform(x[perm]), ir.transform(x)[perm])
2626

27+
# check it doesn't change y when all x are equal:
28+
ir = IsotonicRegression()
29+
assert_array_equal(ir.fit_transform(np.ones(len(x)), y), y)
30+
2731

2832
def test_assert_raises_exceptions():
2933
ir = IsotonicRegression()

0 commit comments

Comments
 (0)