__init__.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. """
  2. Machine learning module for Python
  3. ==================================
  4. sklearn is a Python module integrating classical machine
  5. learning algorithms in the tightly-knit world of scientific Python
  6. packages (numpy, scipy, matplotlib).
  7. It aims to provide simple and efficient solutions to learning problems
  8. that are accessible to everybody and reusable in various contexts:
  9. machine-learning as a versatile tool for science and engineering.
  10. See http://scikit-learn.org for complete documentation.
  11. """
  12. import logging
  13. import os
  14. import random
  15. import sys
  16. from ._config import config_context, get_config, set_config
  17. logger = logging.getLogger(__name__)
  18. # PEP0440 compatible formatted version, see:
  19. # https://www.python.org/dev/peps/pep-0440/
  20. #
  21. # Generic release markers:
  22. # X.Y.0 # For first release after an increment in Y
  23. # X.Y.Z # For bugfix releases
  24. #
  25. # Admissible pre-release markers:
  26. # X.Y.ZaN # Alpha release
  27. # X.Y.ZbN # Beta release
  28. # X.Y.ZrcN # Release Candidate
  29. # X.Y.Z # Final release
  30. #
  31. # Dev branch marker is: 'X.Y.dev' or 'X.Y.devN' where N is an integer.
  32. # 'X.Y.dev0' is the canonical version of 'X.Y.dev'
  33. #
  34. __version__ = "1.3.2"
  35. # On OSX, we can get a runtime error due to multiple OpenMP libraries loaded
  36. # simultaneously. This can happen for instance when calling BLAS inside a
  37. # prange. Setting the following environment variable allows multiple OpenMP
  38. # libraries to be loaded. It should not degrade performances since we manually
  39. # take care of potential over-subcription performance issues, in sections of
  40. # the code where nested OpenMP loops can happen, by dynamically reconfiguring
  41. # the inner OpenMP runtime to temporarily disable it while under the scope of
  42. # the outer OpenMP parallel section.
  43. os.environ.setdefault("KMP_DUPLICATE_LIB_OK", "True")
  44. # Workaround issue discovered in intel-openmp 2019.5:
  45. # https://github.com/ContinuumIO/anaconda-issues/issues/11294
  46. os.environ.setdefault("KMP_INIT_AT_FORK", "FALSE")
  47. try:
  48. # This variable is injected in the __builtins__ by the build
  49. # process. It is used to enable importing subpackages of sklearn when
  50. # the binaries are not built
  51. # mypy error: Cannot determine type of '__SKLEARN_SETUP__'
  52. __SKLEARN_SETUP__ # type: ignore
  53. except NameError:
  54. __SKLEARN_SETUP__ = False
  55. if __SKLEARN_SETUP__:
  56. sys.stderr.write("Partial import of sklearn during the build process.\n")
  57. # We are not importing the rest of scikit-learn during the build
  58. # process, as it may not be compiled yet
  59. else:
  60. # `_distributor_init` allows distributors to run custom init code.
  61. # For instance, for the Windows wheel, this is used to pre-load the
  62. # vcomp shared library runtime for OpenMP embedded in the sklearn/.libs
  63. # sub-folder.
  64. # It is necessary to do this prior to importing show_versions as the
  65. # later is linked to the OpenMP runtime to make it possible to introspect
  66. # it and importing it first would fail if the OpenMP dll cannot be found.
  67. from . import (
  68. __check_build, # noqa: F401
  69. _distributor_init, # noqa: F401
  70. )
  71. from .base import clone
  72. from .utils._show_versions import show_versions
  73. __all__ = [
  74. "calibration",
  75. "cluster",
  76. "covariance",
  77. "cross_decomposition",
  78. "datasets",
  79. "decomposition",
  80. "dummy",
  81. "ensemble",
  82. "exceptions",
  83. "experimental",
  84. "externals",
  85. "feature_extraction",
  86. "feature_selection",
  87. "gaussian_process",
  88. "inspection",
  89. "isotonic",
  90. "kernel_approximation",
  91. "kernel_ridge",
  92. "linear_model",
  93. "manifold",
  94. "metrics",
  95. "mixture",
  96. "model_selection",
  97. "multiclass",
  98. "multioutput",
  99. "naive_bayes",
  100. "neighbors",
  101. "neural_network",
  102. "pipeline",
  103. "preprocessing",
  104. "random_projection",
  105. "semi_supervised",
  106. "svm",
  107. "tree",
  108. "discriminant_analysis",
  109. "impute",
  110. "compose",
  111. # Non-modules:
  112. "clone",
  113. "get_config",
  114. "set_config",
  115. "config_context",
  116. "show_versions",
  117. ]
  118. def setup_module(module):
  119. """Fixture for the tests to assure globally controllable seeding of RNGs"""
  120. import numpy as np
  121. # Check if a random seed exists in the environment, if not create one.
  122. _random_seed = os.environ.get("SKLEARN_SEED", None)
  123. if _random_seed is None:
  124. _random_seed = np.random.uniform() * np.iinfo(np.int32).max
  125. _random_seed = int(_random_seed)
  126. print("I: Seeding RNGs with %r" % _random_seed)
  127. np.random.seed(_random_seed)
  128. random.seed(_random_seed)