From e0f22a99bf3e9af38023a38d7f034d9fbafe871a Mon Sep 17 00:00:00 2001 From: martin-hahn <martin.hahn@blue-yonder.com> Date: Thu, 30 Mar 2017 14:14:02 +0200 Subject: [PATCH] [MRG+1] Calculate confidence intervall only if we have enough samples (#8621) * calculate confidence intervall only if we have enough samples * pep8 * removed parentheses --- sklearn/isotonic.py | 2 +- sklearn/tests/test_isotonic.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/sklearn/isotonic.py b/sklearn/isotonic.py index f3e86b9813..910c235085 100644 --- a/sklearn/isotonic.py +++ b/sklearn/isotonic.py @@ -57,7 +57,7 @@ def check_increasing(x, y): increasing_bool = rho >= 0 # Run Fisher transform to get the rho CI, but handle rho=+/-1 - if rho not in [-1.0, 1.0]: + if rho not in [-1.0, 1.0] and len(x) > 3: F = 0.5 * math.log((1. + rho) / (1. - rho)) F_se = 1 / math.sqrt(len(x) - 3) diff --git a/sklearn/tests/test_isotonic.py b/sklearn/tests/test_isotonic.py index 7abadaf562..d5d0715a0f 100644 --- a/sklearn/tests/test_isotonic.py +++ b/sklearn/tests/test_isotonic.py @@ -27,6 +27,14 @@ def test_permutation_invariance(): assert_array_equal(y_transformed, y_transformed_s) +def test_check_increasing_small_number_of_samples(): + x = [0, 1, 2] + y = [1, 1.1, 1.05] + + is_increasing = assert_no_warnings(check_increasing, x, y) + assert_true(is_increasing) + + def test_check_increasing_up(): x = [0, 1, 2, 3, 4, 5] y = [0, 1.5, 2.77, 8.99, 8.99, 50] -- GitLab