Skip to content

Flaky tests in logistic regression #8879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jl2922 opened this issue May 14, 2017 · 12 comments
Closed

Flaky tests in logistic regression #8879

jl2922 opened this issue May 14, 2017 · 12 comments

Comments

@jl2922
Copy link

jl2922 commented May 14, 2017

@glemaitre #8872

In current master branch

1de66a0

If you run the following commands several times

nosetests sklearn/linear_model/

Some tests related to comparing results between two methods fail randomly.

Instead of comparing with each other, maybe we can use the following test case:
x1 x2 y
1 2 0
2 3 0
3 5 1
4 7 0
5 11 1
6 13 1
For this case, I checked in two statistical tools, a professional one, R, and a casual one, google docs, that the result agrees with each other to the digits shown below:

,Coefficients,Standard Error
Intercept,-2.942920409,3.47036
X Variable 1,-0.9491680059,3.97308
X Variable 2,0.9755542466,1.89720

@jnothman
Copy link
Member

jnothman commented May 14, 2017 via email

@jl2922
Copy link
Author

jl2922 commented May 14, 2017

in the file test_logistic, the tests that compares the coef_ from two methods, like saga vs liblinear

@glemaitre
Copy link
Member

And do you have a hint to achieve the failing condition. I tried to run 10 times but I did not succeed.

Also, if you can provide you system info:

import platform; print(platform.platform())
import sys; print("Python", sys.version)
import numpy; print("NumPy", numpy.__version__)
import scipy; print("SciPy", scipy.__version__)
import sklearn; print("Scikit-Learn", sklearn.__version__)

@jl2922
Copy link
Author

jl2922 commented May 14, 2017

I see. It could be a dependency issue.

Darwin-16.5.0-x86_64-i386-64bit
('Python', '2.7.13 |Anaconda custom (x86_64)| (default, Dec 20 2016, 23:05:08) \n[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]')
('NumPy', '1.9.3')
('SciPy', '0.16.0')
('Scikit-Learn', '0.19.dev0')

@jl2922
Copy link
Author

jl2922 commented May 14, 2017

I just updated some packages and still got fails.

Darwin-16.5.0-x86_64-i386-64bit
('Python', '2.7.13 |Anaconda custom (x86_64)| (default, Dec 20 2016, 23:05:08) \n[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]')
('NumPy', '1.12.1')
('SciPy', '0.19.0')
('Scikit-Learn', '0.19.dev0')

@yanlin-duan
Copy link

@jl2922 Confirmed that the same issue occurred on my side as well. test_saga_vs_liblinear fails ~70% of the time.

Below are my system info:

Darwin-16.5.0-x86_64-i386-64bit
Python 3.5.2 |Anaconda custom (x86_64)| (default, Jul 2 2016, 17:52:12)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)]
NumPy 1.11.3
SciPy 0.18.1
Scikit-Learn 0.19.dev0

I have also extracted out a failed case (data: failed_X and failed_y, fitted model: failed_saga and failed_liblinear) which may help to reproduce the error.

I am still looking at it, but at the first glimpse it seems a bit peculiar for saga solver to have coefficients as huge as -5.623e+177.

test_saga_vs_liblinear_fail_case.zip

@glemaitre
Copy link
Member

My neighbor with the following config reproduce the same error.

Python 3.5.2 |Anaconda 4.3.1 (x86_64)| (default, Jul 2 2016, 17:52:12)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)]
NumPy 1.11.3
SciPy 0.18.1
Scikit-Learn 0.19.dev0

@jnothman @ogrisel @lesteve it seems that there is something specific with Darwin and Anaconda

@lesteve
Copy link
Member

lesteve commented May 23, 2017

Maybe some floating point difference? Maybe dependent on the linear algebra library that is being used?

@glemaitre can you kindly ask your neighbor to post the nosetests or pytest command to run one of the tests failing + the stacktrace?

@glemaitre
Copy link
Member

@dengemann (he might to be away this week)

nosetests or pytest command to run one

I asked for nosetests sklearn/linear_model/tests/test_logistic.py.

@dengemann
Copy link
Contributor

dengemann commented May 23, 2017 via email

@melgoetz
Copy link
Contributor

melgoetz commented Jul 15, 2017

I just had this happen to me as well.

Darwin-16.6.0-x86_64-i386-64bit
Python 3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 13:04:09)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]
NumPy 1.13.1
SciPy 0.19.1
Scikit-Learn 0.20.dev0
➭ nosetests sklearn/linear_model/tests/test_logistic.py
...................../Users/melaniegoetz/git/scikit-learn/sklearn/linear_model/sag.py:326: ConvergenceWarning: The max_iter was reached which means the coef_ did not converge
  "the coef_ did not converge", ConvergenceWarning)
......iter  1 act 8.747e+00 pre 7.841e+00 delta 1.521e+00 f 1.386e+01 |g| 1.607e+01 CG   3
iter  2 act 9.618e-01 pre 8.065e-01 delta 1.521e+00 f 5.116e+00 |g| 3.834e+00 CG   2
./Users/melaniegoetz/git/scikit-learn/sklearn/linear_model/sag.py:326: ConvergenceWarning: The max_iter was reached which means the coef_ did not converge
  "the coef_ did not converge", ConvergenceWarning)
.......F...../Users/melaniegoetz/git/scikit-learn/sklearn/linear_model/sag.py:326: ConvergenceWarning: The max_iter was reached which means the coef_ did not converge
  "the coef_ did not converge", ConvergenceWarning)
F.
======================================================================
FAIL: sklearn.linear_model.tests.test_logistic.test_logreg_l1
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/melaniegoetz/miniconda3/envs/sklearndev/lib/python3.6/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/Users/melaniegoetz/git/scikit-learn/sklearn/linear_model/tests/test_logistic.py", line 930, in test_logreg_l1
    assert_array_almost_equal(lr_saga.coef_, lr_liblinear.coef_)
  File "/Users/melaniegoetz/miniconda3/envs/sklearndev/lib/python3.6/site-packages/numpy/testing/utils.py", line 962, in assert_array_almost_equal
    precision=decimal)
  File "/Users/melaniegoetz/miniconda3/envs/sklearndev/lib/python3.6/site-packages/numpy/testing/utils.py", line 778, in assert_array_compare
    raise AssertionError(msg)
AssertionError:
Arrays are not almost equal to 6 decimals

(mismatch 100.0%)
 x: array([[ 16554.14284 ,  12638.782254,  -7736.068316,  15584.072418,
         -2219.832932, -69260.451715, -92176.31246 ,   7751.559091,
         -4640.8965  ,   7621.556785,  10650.712029,   2845.788903,...
 y: array([[ 0.      ,  0.      ,  0.395495,  0.      ,  0.      ,  0.      ,
         3.527385,  0.      ,  0.      ,  0.      , -0.239079,  0.      ,
         0.      , -0.271122,  0.      ,  0.      ,  0.190561,  0.      ,...
>>  raise AssertionError('\nArrays are not almost equal to 6 decimals\n\n(mismatch 100.0%)\n x: array([[ 16554.14284 ,  12638.782254,  -7736.068316,  15584.072418,\n         -2219.832932, -69260.451715, -92176.31246 ,   7751.559091,\n         -4640.8965  ,   7621.556785,  10650.712029,   2845.788903,...\n y: array([[ 0.      ,  0.      ,  0.395495,  0.      ,  0.      ,  0.      ,\n         3.527385,  0.      ,  0.      ,  0.      , -0.239079,  0.      ,\n         0.      , -0.271122,  0.      ,  0.      ,  0.190561,  0.      ,...')


======================================================================
FAIL: sklearn.linear_model.tests.test_logistic.test_saga_vs_liblinear
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/melaniegoetz/miniconda3/envs/sklearndev/lib/python3.6/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/Users/melaniegoetz/git/scikit-learn/sklearn/linear_model/tests/test_logistic.py", line 1144, in test_saga_vs_liblinear
    assert_array_almost_equal(saga.coef_, liblinear.coef_, 3)
  File "/Users/melaniegoetz/miniconda3/envs/sklearndev/lib/python3.6/site-packages/numpy/testing/utils.py", line 962, in assert_array_almost_equal
    precision=decimal)
  File "/Users/melaniegoetz/miniconda3/envs/sklearndev/lib/python3.6/site-packages/numpy/testing/utils.py", line 778, in assert_array_compare
    raise AssertionError(msg)
AssertionError:
Arrays are not almost equal to 3 decimals

(mismatch 100.0%)
 x: array([[-1758.151, -6326.522,  9487.076,  3625.029]])
 y: array([[ 0.   , -1.06 ,  1.222,  0.   ]])
>>  raise AssertionError('\nArrays are not almost equal to 3 decimals\n\n(mismatch 100.0%)\n x: array([[-1758.151, -6326.522,  9487.076,  3625.029]])\n y: array([[ 0.   , -1.06 ,  1.222,  0.   ]])')


----------------------------------------------------------------------
Ran 43 tests in 4.795s

FAILED (failures=2)

@TomDLT
Copy link
Member

TomDLT commented Jul 17, 2017

This issue seems to be identical to #9351, solved in #9376.

I guess we can close it.

@TomDLT TomDLT closed this as completed Jul 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants