Skip to content

TST: test_predict_proba_binary fails for some random seed #12762

Closed

Description

@wdevazelhes

Description

test_predict_proba_binary fails with some random seed. I encountered this during PR #10058 , modifying by mistake the random state in tests

Steps/Code to Reproduce

from sklearn.neural_network.tests.test_mlp import test_predict_proba_binary
np.random.seed(2)
test_predict_proba_binary()

Expected Results

No error is thrown

Actual Results

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-1-54c5d3efee13> in <module>
      1 from sklearn.neural_network.tests.test_mlp import test_predict_proba_binary
      2 np.random.seed(2)
----> 3 test_predict_proba_binary()

~/anaconda3/envs/env_test_mlp/lib/python3.7/site-packages/sklearn/neural_network/tests/test_mlp.py in test_predict_proba_binary()
    448     assert_array_equal(y_log_proba, np.log(y_proba))
    449 
--> 450     assert_equal(roc_auc_score(y, y_proba[:, 1]), 1.0)
    451 
    452 

~/anaconda3/envs/env_test_mlp/lib/python3.7/unittest/case.py in assertEqual(self, first, second, msg)
    837         """
    838         assertion_func = self._getAssertEqualityFunc(first, second)
--> 839         assertion_func(first, second, msg=msg)
    840 
    841     def assertNotEqual(self, first, second, msg=None):

~/anaconda3/envs/env_test_mlp/lib/python3.7/unittest/case.py in _baseAssertEqual(self, first, second, msg)
    830             standardMsg = '%s != %s' % _common_shorten_repr(first, second)
    831             msg = self._formatMessage(msg, standardMsg)
--> 832             raise self.failureException(msg)
    833 
    834     def assertEqual(self, first, second, msg=None):

AssertionError: 0.5 != 1.0

Versions

System:
    python: 3.7.1 (default, Oct 23 2018, 19:19:42)  [GCC 7.3.0]
executable: /home/will/anaconda3/envs/env_test_mlp/bin/python
   machine: Linux-4.4.0-139-generic-x86_64-with-debian-stretch-sid

BLAS:
    macros: SCIPY_MKL_H=None, HAVE_CBLAS=None
  lib_dirs: /home/will/anaconda3/envs/env_test_mlp/lib
cblas_libs: mkl_rt, pthread

Python deps:
       pip: 18.1
setuptools: 40.6.2
   sklearn: 0.21.dev0
     numpy: 1.15.4
     scipy: 1.1.0
    Cython: None
    pandas: None

Activity

  1. jnothman commented on Dec 12, 2018

    @jnothman
    Member

    So the test should at least fix its random seed... or we need a stronger test.

  2. added
    Easy
    good first issue
    on Dec 12, 2018
  3. xhan7279 commented on Dec 14, 2018

    @xhan7279
    Contributor

    First timer here. I took a look at the test and am not sure why the random state would affect the output of MLPClassifier. Specifying a random state when initializing the classifier does fix the issue. Should I go ahead?

  4. adrinjalali commented on Dec 16, 2018

    @adrinjalali
    Member

    Sure, go ahead @xhan7279 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Easygood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions