Skip to content

Commit

Permalink
DEBUG print
Browse files Browse the repository at this point in the history
  • Loading branch information
lorentzenchr committed May 10, 2024
1 parent 4ca6e8b commit fb793e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sklearn/isotonic.py
Expand Up @@ -154,10 +154,18 @@ def isotonic_regression(
"""
y = check_array(y, ensure_2d=False, input_name="y", dtype=[np.float64, np.float32])
if sp_base_version >= parse_version("1.12.0"):
do_print = y.shape == (7,) and np.allclose(
y, np.array([10, 9, 10, 7, 6, 6.1, 5])
)
if do_print:
print("DEBUG INFO:")
print(f"increasing={increasing} sw={sample_weight}\ny={y}")
res = optimize.isotonic_regression(
y=y, weights=sample_weight, increasing=increasing
)
y = np.asarray(res.x, dtype=y.dtype)
if do_print:
print(f"After isotonic_regression:\ny={y}")
else:
# TODO: remove this branch when Scipy 1.12 is the minimum supported version
# Also remove _inplace_contiguous_isotonic_regression.
Expand Down
6 changes: 6 additions & 0 deletions sklearn/tests/test_isotonic.py
Expand Up @@ -227,7 +227,13 @@ def test_isotonic_regression_with_ties_in_differently_sized_groups():

def test_isotonic_regression_reversed():
y = np.array([10, 9, 10, 7, 6, 6.1, 5])
y_result = np.array([10, 9.5, 9.5, 7, 6.05, 6.05, 5])

y_iso = isotonic_regression(y, increasing=False)
assert_allclose(y_iso, y_result)

y_ = IsotonicRegression(increasing=False).fit_transform(np.arange(len(y)), y)
assert_allclose(y_, y_result)
assert_array_equal(np.ones(y_[:-1].shape), ((y_[:-1] - y_[1:]) >= 0))


Expand Down

0 comments on commit fb793e7

Please sign in to comment.