Repository: scikit-learn/scikit-learn
Pull request: [MRG+1] Calculate confidence intervall only if we have enough samples

#### Reference Issue
 Fixes #8620


#### What does this implement/fix? Explain your changes.
To calculate frequentist standard errors we need at least 4 data points.
I checked for this requirement and did not enter the buggy calculation. 


Problem statement:
sklearn.isotonic.check_increasing(x,y) crashes if len(x) < 4
The following code (scikit-learn==0.17.1):


`import numpy as np`
`from sklearn.isotonic import check_increasing`
`n = 2`
`check_increasing(np.arange(n), np.ones(n))`

crashes with the following error message:


`  File "bug.py", line 4, in <module>`
`    check_increasing(np.arange(n), np.ones(n))`
`  File "/home/vagrant/venvs/venv/local/lib/python2.7/site-packages/sklearn/isotonic.py", line 61, in check_increasing`
  `  F_se = 1 / math.sqrt(len(x) - 3)`
`ValueError: math domain error`

Hints from issue discussion:
Indeed it is still in master. PR more than welcome. I am not sure what the right fix is to be honest.
I have done a bug fix and i am happy to push it and create a pull request

Commit message: pep8

Patch to review:
diff --git a/sklearn/isotonic.py b/sklearn/isotonic.py
index f3e86b9813429..8930cce559189 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 7abadaf562d94..d5d0715a0fb7f 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]


Code review comments:
diff_hunk: @@ -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):
path: sklearn/isotonic.py
text: @user1:
Python is not C, you don't need the parentheses around boolean conditions. Replace this by:
```py
if rho not in [-1.0, 1.0] and len(x) > 3:
```