Skip to content

Don't use global np.random.seed in tests #13345

@rth

Description

@rth

A few tests and doctests are currently setting np.random.seed globally. Unless I'm missing something, we should avoid that as it has the potential to both

  • affect other tests (if those don't set the random seed explicitly
  • hurt reproducibility: e.g. tests that don't set a random_state may behave deterministically because of this when run as part of the full test suite (given that test order is deterministic now) but yield another result when run separately.
sklearn/random_projection.py
591:    >>> np.random.seed(42)

sklearn/covariance/empirical_covariance_.py
123:    >>> np.random.seed(0)

sklearn/covariance/shrunk_covariance_.py
106:    >>> np.random.seed(0)
374:    >>> np.random.seed(0)

sklearn/covariance/robust_covariance.py
589:    >>> np.random.seed(0)

sklearn/linear_model/huber.py
199:    >>> np.random.seed(0)

sklearn/linear_model/sag.py
204:    >>> np.random.seed(0)

sklearn/linear_model/ridge.py
643:    >>> np.random.seed(0)

sklearn/linear_model/stochastic_gradient.py
1562:    >>> np.random.seed(0)

sklearn/model_selection/_search.py
231:    >>> np.random.seed(0)

sklearn/__init__.py
95:    np.random.seed(_random_seed)

sklearn/svm/classes.py
877:    >>> np.random.seed(0)
1004:    >>> np.random.seed(0)

sklearn/neighbors/binary_tree.pxi
303:    >>> np.random.seed(0)
317:    >>> np.random.seed(0)
331:    >>> np.random.seed(0)
344:    >>> np.random.seed(1)
353:    >>> np.random.seed(0)

sklearn/decomposition/tests/test_fastica.py
57:    np.random.seed(0)

sklearn/neighbors/tests/test_ball_tree.py
155:    np.random.seed(0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    EasyWell-defined and straightforward way to resolvegood first issueEasy with clear instructions to resolvehelp wanted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions