Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/scikit_learn-1.4.dev0-py3.8-linux-x86_64.egg/sklearn/__init__.py: 68%

28 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-12-12 06:31 +0000

1""" 

2The :mod:`sklearn` module includes functions to configure global settings and 

3get information about the working environment. 

4""" 

5 

6# Machine learning module for Python 

7# ================================== 

8# 

9# sklearn is a Python module integrating classical machine 

10# learning algorithms in the tightly-knit world of scientific Python 

11# packages (numpy, scipy, matplotlib). 

12# 

13# It aims to provide simple and efficient solutions to learning problems 

14# that are accessible to everybody and reusable in various contexts: 

15# machine-learning as a versatile tool for science and engineering. 

16# 

17# See http://scikit-learn.org for complete documentation. 

18 

19import logging 

20import os 

21import random 

22import sys 

23 

24from ._config import config_context, get_config, set_config 

25 

26logger = logging.getLogger(__name__) 

27 

28 

29# PEP0440 compatible formatted version, see: 

30# https://www.python.org/dev/peps/pep-0440/ 

31# 

32# Generic release markers: 

33# X.Y.0 # For first release after an increment in Y 

34# X.Y.Z # For bugfix releases 

35# 

36# Admissible pre-release markers: 

37# X.Y.ZaN # Alpha release 

38# X.Y.ZbN # Beta release 

39# X.Y.ZrcN # Release Candidate 

40# X.Y.Z # Final release 

41# 

42# Dev branch marker is: 'X.Y.dev' or 'X.Y.devN' where N is an integer. 

43# 'X.Y.dev0' is the canonical version of 'X.Y.dev' 

44# 

45__version__ = "1.4.dev0" 

46 

47 

48# On OSX, we can get a runtime error due to multiple OpenMP libraries loaded 

49# simultaneously. This can happen for instance when calling BLAS inside a 

50# prange. Setting the following environment variable allows multiple OpenMP 

51# libraries to be loaded. It should not degrade performances since we manually 

52# take care of potential over-subcription performance issues, in sections of 

53# the code where nested OpenMP loops can happen, by dynamically reconfiguring 

54# the inner OpenMP runtime to temporarily disable it while under the scope of 

55# the outer OpenMP parallel section. 

56os.environ.setdefault("KMP_DUPLICATE_LIB_OK", "True") 

57 

58# Workaround issue discovered in intel-openmp 2019.5: 

59# https://github.com/ContinuumIO/anaconda-issues/issues/11294 

60os.environ.setdefault("KMP_INIT_AT_FORK", "FALSE") 

61 

62try: 

63 # This variable is injected in the __builtins__ by the build 

64 # process. It is used to enable importing subpackages of sklearn when 

65 # the binaries are not built 

66 # mypy error: Cannot determine type of '__SKLEARN_SETUP__' 

67 __SKLEARN_SETUP__ # type: ignore 

68except NameError: 

69 __SKLEARN_SETUP__ = False 

70 

71if __SKLEARN_SETUP__: 

72 sys.stderr.write("Partial import of sklearn during the build process.\n") 

73 # We are not importing the rest of scikit-learn during the build 

74 # process, as it may not be compiled yet 

75else: 

76 # `_distributor_init` allows distributors to run custom init code. 

77 # For instance, for the Windows wheel, this is used to pre-load the 

78 # vcomp shared library runtime for OpenMP embedded in the sklearn/.libs 

79 # sub-folder. 

80 # It is necessary to do this prior to importing show_versions as the 

81 # later is linked to the OpenMP runtime to make it possible to introspect 

82 # it and importing it first would fail if the OpenMP dll cannot be found. 

83 from . import ( 

84 __check_build, # noqa: F401 

85 _distributor_init, # noqa: F401 

86 ) 

87 from .base import clone 

88 from .utils._show_versions import show_versions 

89 

90 __all__ = [ 

91 "calibration", 

92 "cluster", 

93 "covariance", 

94 "cross_decomposition", 

95 "datasets", 

96 "decomposition", 

97 "dummy", 

98 "ensemble", 

99 "exceptions", 

100 "experimental", 

101 "externals", 

102 "feature_extraction", 

103 "feature_selection", 

104 "gaussian_process", 

105 "inspection", 

106 "isotonic", 

107 "kernel_approximation", 

108 "kernel_ridge", 

109 "linear_model", 

110 "manifold", 

111 "metrics", 

112 "mixture", 

113 "model_selection", 

114 "multiclass", 

115 "multioutput", 

116 "naive_bayes", 

117 "neighbors", 

118 "neural_network", 

119 "pipeline", 

120 "preprocessing", 

121 "random_projection", 

122 "semi_supervised", 

123 "svm", 

124 "tree", 

125 "discriminant_analysis", 

126 "impute", 

127 "compose", 

128 # Non-modules: 

129 "clone", 

130 "get_config", 

131 "set_config", 

132 "config_context", 

133 "show_versions", 

134 ] 

135 

136 

137def setup_module(module): 

138 """Fixture for the tests to assure globally controllable seeding of RNGs""" 

139 

140 import numpy as np 

141 

142 # Check if a random seed exists in the environment, if not create one. 

143 _random_seed = os.environ.get("SKLEARN_SEED", None) 

144 if _random_seed is None: 

145 _random_seed = np.random.uniform() * np.iinfo(np.int32).max 

146 _random_seed = int(_random_seed) 

147 print("I: Seeding RNGs with %r" % _random_seed) 

148 np.random.seed(_random_seed) 

149 random.seed(_random_seed)