scikit-learn-intelex 2025.0.0__py310-none-manylinux_2_28_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of scikit-learn-intelex might be problematic. Click here for more details.

Files changed (278) hide show
  1. daal4py/__init__.py +73 -0
  2. daal4py/__main__.py +58 -0
  3. daal4py/_daal4py.cpython-310-x86_64-linux-gnu.so +0 -0
  4. daal4py/doc/third-party-programs.txt +424 -0
  5. daal4py/mb/__init__.py +19 -0
  6. daal4py/mb/model_builders.py +377 -0
  7. daal4py/mpi_transceiver.cpython-310-x86_64-linux-gnu.so +0 -0
  8. daal4py/sklearn/__init__.py +40 -0
  9. daal4py/sklearn/_n_jobs_support.py +242 -0
  10. daal4py/sklearn/_utils.py +241 -0
  11. daal4py/sklearn/cluster/__init__.py +20 -0
  12. daal4py/sklearn/cluster/dbscan.py +165 -0
  13. daal4py/sklearn/cluster/k_means.py +597 -0
  14. daal4py/sklearn/cluster/tests/test_dbscan.py +109 -0
  15. daal4py/sklearn/decomposition/__init__.py +19 -0
  16. daal4py/sklearn/decomposition/_pca.py +524 -0
  17. daal4py/sklearn/ensemble/AdaBoostClassifier.py +192 -0
  18. daal4py/sklearn/ensemble/GBTDAAL.py +318 -0
  19. daal4py/sklearn/ensemble/__init__.py +27 -0
  20. daal4py/sklearn/ensemble/_forest.py +1397 -0
  21. daal4py/sklearn/ensemble/tests/test_decision_forest.py +206 -0
  22. daal4py/sklearn/linear_model/__init__.py +29 -0
  23. daal4py/sklearn/linear_model/_coordinate_descent.py +848 -0
  24. daal4py/sklearn/linear_model/_linear.py +272 -0
  25. daal4py/sklearn/linear_model/_ridge.py +325 -0
  26. daal4py/sklearn/linear_model/coordinate_descent.py +17 -0
  27. daal4py/sklearn/linear_model/linear.py +17 -0
  28. daal4py/sklearn/linear_model/logistic_loss.py +195 -0
  29. daal4py/sklearn/linear_model/logistic_path.py +1026 -0
  30. daal4py/sklearn/linear_model/ridge.py +17 -0
  31. daal4py/sklearn/linear_model/tests/test_linear.py +196 -0
  32. daal4py/sklearn/linear_model/tests/test_ridge.py +69 -0
  33. daal4py/sklearn/manifold/__init__.py +19 -0
  34. daal4py/sklearn/manifold/_t_sne.py +405 -0
  35. daal4py/sklearn/metrics/__init__.py +20 -0
  36. daal4py/sklearn/metrics/_pairwise.py +155 -0
  37. daal4py/sklearn/metrics/_ranking.py +210 -0
  38. daal4py/sklearn/model_selection/__init__.py +19 -0
  39. daal4py/sklearn/model_selection/_split.py +309 -0
  40. daal4py/sklearn/model_selection/tests/test_split.py +56 -0
  41. daal4py/sklearn/monkeypatch/__init__.py +0 -0
  42. daal4py/sklearn/monkeypatch/dispatcher.py +232 -0
  43. daal4py/sklearn/monkeypatch/tests/_models_info.py +161 -0
  44. daal4py/sklearn/monkeypatch/tests/test_monkeypatch.py +71 -0
  45. daal4py/sklearn/monkeypatch/tests/test_patching.py +87 -0
  46. daal4py/sklearn/monkeypatch/tests/utils/_launch_algorithms.py +118 -0
  47. daal4py/sklearn/neighbors/__init__.py +21 -0
  48. daal4py/sklearn/neighbors/_base.py +503 -0
  49. daal4py/sklearn/neighbors/_classification.py +139 -0
  50. daal4py/sklearn/neighbors/_regression.py +74 -0
  51. daal4py/sklearn/neighbors/_unsupervised.py +55 -0
  52. daal4py/sklearn/neighbors/tests/test_kneighbors.py +113 -0
  53. daal4py/sklearn/svm/__init__.py +19 -0
  54. daal4py/sklearn/svm/svm.py +734 -0
  55. daal4py/sklearn/utils/__init__.py +21 -0
  56. daal4py/sklearn/utils/base.py +75 -0
  57. daal4py/sklearn/utils/tests/test_utils.py +51 -0
  58. daal4py/sklearn/utils/validation.py +693 -0
  59. onedal/__init__.py +83 -0
  60. onedal/_config.py +53 -0
  61. onedal/_device_offload.py +229 -0
  62. onedal/_onedal_py_dpc.cpython-310-x86_64-linux-gnu.so +0 -0
  63. onedal/_onedal_py_host.cpython-310-x86_64-linux-gnu.so +0 -0
  64. onedal/_onedal_py_spmd_dpc.cpython-310-x86_64-linux-gnu.so +0 -0
  65. onedal/basic_statistics/__init__.py +20 -0
  66. onedal/basic_statistics/basic_statistics.py +107 -0
  67. onedal/basic_statistics/incremental_basic_statistics.py +160 -0
  68. onedal/basic_statistics/tests/test_basic_statistics.py +298 -0
  69. onedal/basic_statistics/tests/test_incremental_basic_statistics.py +196 -0
  70. onedal/cluster/__init__.py +27 -0
  71. onedal/cluster/dbscan.py +110 -0
  72. onedal/cluster/kmeans.py +560 -0
  73. onedal/cluster/kmeans_init.py +115 -0
  74. onedal/cluster/tests/test_dbscan.py +125 -0
  75. onedal/cluster/tests/test_kmeans.py +88 -0
  76. onedal/cluster/tests/test_kmeans_init.py +93 -0
  77. onedal/common/_base.py +38 -0
  78. onedal/common/_estimator_checks.py +47 -0
  79. onedal/common/_mixin.py +62 -0
  80. onedal/common/_policy.py +59 -0
  81. onedal/common/_spmd_policy.py +30 -0
  82. onedal/common/hyperparameters.py +116 -0
  83. onedal/common/tests/test_policy.py +75 -0
  84. onedal/covariance/__init__.py +20 -0
  85. onedal/covariance/covariance.py +125 -0
  86. onedal/covariance/incremental_covariance.py +146 -0
  87. onedal/covariance/tests/test_covariance.py +50 -0
  88. onedal/covariance/tests/test_incremental_covariance.py +122 -0
  89. onedal/datatypes/__init__.py +19 -0
  90. onedal/datatypes/_data_conversion.py +95 -0
  91. onedal/datatypes/tests/test_data.py +235 -0
  92. onedal/decomposition/__init__.py +20 -0
  93. onedal/decomposition/incremental_pca.py +204 -0
  94. onedal/decomposition/pca.py +186 -0
  95. onedal/decomposition/tests/test_incremental_pca.py +198 -0
  96. onedal/ensemble/__init__.py +29 -0
  97. onedal/ensemble/forest.py +720 -0
  98. onedal/ensemble/tests/test_random_forest.py +97 -0
  99. onedal/linear_model/__init__.py +27 -0
  100. onedal/linear_model/incremental_linear_model.py +258 -0
  101. onedal/linear_model/linear_model.py +329 -0
  102. onedal/linear_model/logistic_regression.py +249 -0
  103. onedal/linear_model/tests/test_incremental_linear_regression.py +168 -0
  104. onedal/linear_model/tests/test_incremental_ridge_regression.py +107 -0
  105. onedal/linear_model/tests/test_linear_regression.py +149 -0
  106. onedal/linear_model/tests/test_logistic_regression.py +95 -0
  107. onedal/linear_model/tests/test_ridge.py +95 -0
  108. onedal/neighbors/__init__.py +19 -0
  109. onedal/neighbors/neighbors.py +778 -0
  110. onedal/neighbors/tests/test_knn_classification.py +49 -0
  111. onedal/primitives/__init__.py +27 -0
  112. onedal/primitives/get_tree.py +25 -0
  113. onedal/primitives/kernel_functions.py +153 -0
  114. onedal/primitives/tests/test_kernel_functions.py +159 -0
  115. onedal/spmd/__init__.py +25 -0
  116. onedal/spmd/_base.py +30 -0
  117. onedal/spmd/basic_statistics/__init__.py +20 -0
  118. onedal/spmd/basic_statistics/basic_statistics.py +30 -0
  119. onedal/spmd/basic_statistics/incremental_basic_statistics.py +69 -0
  120. onedal/spmd/cluster/__init__.py +28 -0
  121. onedal/spmd/cluster/dbscan.py +23 -0
  122. onedal/spmd/cluster/kmeans.py +56 -0
  123. onedal/spmd/covariance/__init__.py +20 -0
  124. onedal/spmd/covariance/covariance.py +26 -0
  125. onedal/spmd/covariance/incremental_covariance.py +82 -0
  126. onedal/spmd/decomposition/__init__.py +20 -0
  127. onedal/spmd/decomposition/incremental_pca.py +117 -0
  128. onedal/spmd/decomposition/pca.py +26 -0
  129. onedal/spmd/ensemble/__init__.py +19 -0
  130. onedal/spmd/ensemble/forest.py +28 -0
  131. onedal/spmd/linear_model/__init__.py +21 -0
  132. onedal/spmd/linear_model/incremental_linear_model.py +97 -0
  133. onedal/spmd/linear_model/linear_model.py +30 -0
  134. onedal/spmd/linear_model/logistic_regression.py +38 -0
  135. onedal/spmd/neighbors/__init__.py +19 -0
  136. onedal/spmd/neighbors/neighbors.py +75 -0
  137. onedal/svm/__init__.py +19 -0
  138. onedal/svm/svm.py +556 -0
  139. onedal/svm/tests/test_csr_svm.py +351 -0
  140. onedal/svm/tests/test_nusvc.py +204 -0
  141. onedal/svm/tests/test_nusvr.py +210 -0
  142. onedal/svm/tests/test_svc.py +168 -0
  143. onedal/svm/tests/test_svr.py +243 -0
  144. onedal/tests/test_common.py +41 -0
  145. onedal/tests/utils/_dataframes_support.py +168 -0
  146. onedal/tests/utils/_device_selection.py +107 -0
  147. onedal/utils/__init__.py +49 -0
  148. onedal/utils/_array_api.py +91 -0
  149. onedal/utils/validation.py +432 -0
  150. scikit_learn_intelex-2025.0.0.dist-info/LICENSE.txt +202 -0
  151. scikit_learn_intelex-2025.0.0.dist-info/METADATA +231 -0
  152. scikit_learn_intelex-2025.0.0.dist-info/RECORD +278 -0
  153. scikit_learn_intelex-2025.0.0.dist-info/WHEEL +5 -0
  154. scikit_learn_intelex-2025.0.0.dist-info/top_level.txt +3 -0
  155. sklearnex/__init__.py +65 -0
  156. sklearnex/__main__.py +58 -0
  157. sklearnex/_config.py +98 -0
  158. sklearnex/_device_offload.py +121 -0
  159. sklearnex/_utils.py +109 -0
  160. sklearnex/basic_statistics/__init__.py +20 -0
  161. sklearnex/basic_statistics/basic_statistics.py +140 -0
  162. sklearnex/basic_statistics/incremental_basic_statistics.py +288 -0
  163. sklearnex/basic_statistics/tests/test_basic_statistics.py +251 -0
  164. sklearnex/basic_statistics/tests/test_incremental_basic_statistics.py +384 -0
  165. sklearnex/cluster/__init__.py +20 -0
  166. sklearnex/cluster/dbscan.py +192 -0
  167. sklearnex/cluster/k_means.py +383 -0
  168. sklearnex/cluster/tests/test_dbscan.py +38 -0
  169. sklearnex/cluster/tests/test_kmeans.py +153 -0
  170. sklearnex/conftest.py +73 -0
  171. sklearnex/covariance/__init__.py +19 -0
  172. sklearnex/covariance/incremental_covariance.py +368 -0
  173. sklearnex/covariance/tests/test_incremental_covariance.py +226 -0
  174. sklearnex/decomposition/__init__.py +19 -0
  175. sklearnex/decomposition/pca.py +414 -0
  176. sklearnex/decomposition/tests/test_pca.py +58 -0
  177. sklearnex/dispatcher.py +543 -0
  178. sklearnex/doc/third-party-programs.txt +424 -0
  179. sklearnex/ensemble/__init__.py +29 -0
  180. sklearnex/ensemble/_forest.py +2016 -0
  181. sklearnex/ensemble/tests/test_forest.py +120 -0
  182. sklearnex/glob/__main__.py +72 -0
  183. sklearnex/glob/dispatcher.py +101 -0
  184. sklearnex/linear_model/__init__.py +32 -0
  185. sklearnex/linear_model/coordinate_descent.py +30 -0
  186. sklearnex/linear_model/incremental_linear.py +463 -0
  187. sklearnex/linear_model/incremental_ridge.py +418 -0
  188. sklearnex/linear_model/linear.py +302 -0
  189. sklearnex/linear_model/logistic_path.py +17 -0
  190. sklearnex/linear_model/logistic_regression.py +403 -0
  191. sklearnex/linear_model/ridge.py +24 -0
  192. sklearnex/linear_model/tests/test_incremental_linear.py +203 -0
  193. sklearnex/linear_model/tests/test_incremental_ridge.py +153 -0
  194. sklearnex/linear_model/tests/test_linear.py +142 -0
  195. sklearnex/linear_model/tests/test_logreg.py +134 -0
  196. sklearnex/manifold/__init__.py +19 -0
  197. sklearnex/manifold/t_sne.py +21 -0
  198. sklearnex/manifold/tests/test_tsne.py +26 -0
  199. sklearnex/metrics/__init__.py +23 -0
  200. sklearnex/metrics/pairwise.py +22 -0
  201. sklearnex/metrics/ranking.py +20 -0
  202. sklearnex/metrics/tests/test_metrics.py +39 -0
  203. sklearnex/model_selection/__init__.py +21 -0
  204. sklearnex/model_selection/split.py +22 -0
  205. sklearnex/model_selection/tests/test_model_selection.py +34 -0
  206. sklearnex/neighbors/__init__.py +27 -0
  207. sklearnex/neighbors/_lof.py +231 -0
  208. sklearnex/neighbors/common.py +310 -0
  209. sklearnex/neighbors/knn_classification.py +226 -0
  210. sklearnex/neighbors/knn_regression.py +203 -0
  211. sklearnex/neighbors/knn_unsupervised.py +170 -0
  212. sklearnex/neighbors/tests/test_neighbors.py +80 -0
  213. sklearnex/preview/__init__.py +17 -0
  214. sklearnex/preview/covariance/__init__.py +19 -0
  215. sklearnex/preview/covariance/covariance.py +133 -0
  216. sklearnex/preview/covariance/tests/test_covariance.py +66 -0
  217. sklearnex/preview/decomposition/__init__.py +19 -0
  218. sklearnex/preview/decomposition/incremental_pca.py +228 -0
  219. sklearnex/preview/decomposition/tests/test_incremental_pca.py +266 -0
  220. sklearnex/preview/linear_model/__init__.py +19 -0
  221. sklearnex/preview/linear_model/ridge.py +419 -0
  222. sklearnex/preview/linear_model/tests/test_ridge.py +102 -0
  223. sklearnex/spmd/__init__.py +25 -0
  224. sklearnex/spmd/basic_statistics/__init__.py +20 -0
  225. sklearnex/spmd/basic_statistics/basic_statistics.py +21 -0
  226. sklearnex/spmd/basic_statistics/incremental_basic_statistics.py +30 -0
  227. sklearnex/spmd/basic_statistics/tests/test_basic_statistics_spmd.py +107 -0
  228. sklearnex/spmd/basic_statistics/tests/test_incremental_basic_statistics_spmd.py +307 -0
  229. sklearnex/spmd/cluster/__init__.py +30 -0
  230. sklearnex/spmd/cluster/dbscan.py +50 -0
  231. sklearnex/spmd/cluster/kmeans.py +21 -0
  232. sklearnex/spmd/cluster/tests/test_dbscan_spmd.py +97 -0
  233. sklearnex/spmd/cluster/tests/test_kmeans_spmd.py +172 -0
  234. sklearnex/spmd/covariance/__init__.py +20 -0
  235. sklearnex/spmd/covariance/covariance.py +21 -0
  236. sklearnex/spmd/covariance/incremental_covariance.py +37 -0
  237. sklearnex/spmd/covariance/tests/test_covariance_spmd.py +107 -0
  238. sklearnex/spmd/covariance/tests/test_incremental_covariance_spmd.py +184 -0
  239. sklearnex/spmd/decomposition/__init__.py +20 -0
  240. sklearnex/spmd/decomposition/incremental_pca.py +30 -0
  241. sklearnex/spmd/decomposition/pca.py +21 -0
  242. sklearnex/spmd/decomposition/tests/test_incremental_pca_spmd.py +269 -0
  243. sklearnex/spmd/decomposition/tests/test_pca_spmd.py +128 -0
  244. sklearnex/spmd/ensemble/__init__.py +19 -0
  245. sklearnex/spmd/ensemble/forest.py +71 -0
  246. sklearnex/spmd/ensemble/tests/test_forest_spmd.py +265 -0
  247. sklearnex/spmd/linear_model/__init__.py +21 -0
  248. sklearnex/spmd/linear_model/incremental_linear_model.py +35 -0
  249. sklearnex/spmd/linear_model/linear_model.py +21 -0
  250. sklearnex/spmd/linear_model/logistic_regression.py +21 -0
  251. sklearnex/spmd/linear_model/tests/test_incremental_linear_spmd.py +329 -0
  252. sklearnex/spmd/linear_model/tests/test_linear_regression_spmd.py +145 -0
  253. sklearnex/spmd/linear_model/tests/test_logistic_regression_spmd.py +166 -0
  254. sklearnex/spmd/neighbors/__init__.py +19 -0
  255. sklearnex/spmd/neighbors/neighbors.py +25 -0
  256. sklearnex/spmd/neighbors/tests/test_neighbors_spmd.py +288 -0
  257. sklearnex/svm/__init__.py +29 -0
  258. sklearnex/svm/_common.py +328 -0
  259. sklearnex/svm/nusvc.py +332 -0
  260. sklearnex/svm/nusvr.py +148 -0
  261. sklearnex/svm/svc.py +360 -0
  262. sklearnex/svm/svr.py +149 -0
  263. sklearnex/svm/tests/test_svm.py +93 -0
  264. sklearnex/tests/_utils.py +328 -0
  265. sklearnex/tests/_utils_spmd.py +198 -0
  266. sklearnex/tests/test_common.py +54 -0
  267. sklearnex/tests/test_config.py +43 -0
  268. sklearnex/tests/test_memory_usage.py +291 -0
  269. sklearnex/tests/test_monkeypatch.py +276 -0
  270. sklearnex/tests/test_n_jobs_support.py +103 -0
  271. sklearnex/tests/test_parallel.py +48 -0
  272. sklearnex/tests/test_patching.py +385 -0
  273. sklearnex/tests/test_run_to_run_stability.py +296 -0
  274. sklearnex/utils/__init__.py +19 -0
  275. sklearnex/utils/_array_api.py +82 -0
  276. sklearnex/utils/parallel.py +59 -0
  277. sklearnex/utils/tests/test_finite.py +89 -0
  278. sklearnex/utils/validation.py +17 -0
@@ -0,0 +1,432 @@
1
+ # ==============================================================================
2
+ # Copyright 2021 Intel Corporation
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ # ==============================================================================
16
+
17
+ import warnings
18
+ from collections.abc import Sequence
19
+ from numbers import Integral
20
+
21
+ import numpy as np
22
+ from scipy import sparse as sp
23
+
24
+ if np.lib.NumpyVersion(np.__version__) >= np.lib.NumpyVersion("2.0.0a0"):
25
+ # numpy_version >= 2.0
26
+ from numpy.exceptions import VisibleDeprecationWarning
27
+ else:
28
+ # numpy_version < 2.0
29
+ from numpy import VisibleDeprecationWarning
30
+
31
+ from sklearn.preprocessing import LabelEncoder
32
+ from sklearn.utils.validation import check_array
33
+
34
+ from daal4py.sklearn.utils.validation import _assert_all_finite
35
+
36
+
37
+ class DataConversionWarning(UserWarning):
38
+ """Warning used to notify implicit data conversions happening in the code."""
39
+
40
+
41
+ def _is_arraylike(x):
42
+ """Returns whether the input is array-like."""
43
+ return hasattr(x, "__len__") or hasattr(x, "shape") or hasattr(x, "__array__")
44
+
45
+
46
+ def _is_arraylike_not_scalar(array):
47
+ """Return True if array is array-like and not a scalar"""
48
+ return _is_arraylike(array) and not np.isscalar(array)
49
+
50
+
51
+ def _column_or_1d(y, warn=False):
52
+ y = np.asarray(y)
53
+
54
+ # TODO: Convert this kind of arrays to a table like in daal4py
55
+ if not y.flags.aligned and not y.flags.writeable:
56
+ y = np.array(y.tolist())
57
+
58
+ shape = np.shape(y)
59
+ if len(shape) == 1:
60
+ return np.ravel(y)
61
+ if len(shape) == 2 and shape[1] == 1:
62
+ if warn:
63
+ warnings.warn(
64
+ "A column-vector y was passed when a 1d array was"
65
+ " expected. Please change the shape of y to "
66
+ "(n_samples, ), for example using ravel().",
67
+ DataConversionWarning,
68
+ stacklevel=2,
69
+ )
70
+ return np.ravel(y)
71
+
72
+ raise ValueError(
73
+ "y should be a 1d array, " "got an array of shape {} instead.".format(shape)
74
+ )
75
+
76
+
77
+ def _compute_class_weight(class_weight, classes, y):
78
+ if set(y) - set(classes):
79
+ raise ValueError("classes should include all valid labels that can " "be in y")
80
+ if class_weight is None or len(class_weight) == 0:
81
+ weight = np.ones(classes.shape[0], dtype=np.float64, order="C")
82
+ elif class_weight == "balanced":
83
+ y_ = _column_or_1d(y)
84
+ classes, _ = np.unique(y_, return_inverse=True)
85
+
86
+ le = LabelEncoder()
87
+ y_ind = le.fit_transform(y_)
88
+ if not all(np.in1d(classes, le.classes_)):
89
+ raise ValueError("classes should have valid labels that are in y")
90
+
91
+ y_bin = np.bincount(y_ind).astype(np.float64)
92
+ weight = len(y_) / (len(le.classes_) * y_bin)
93
+ else:
94
+ # user-defined dictionary
95
+ weight = np.ones(classes.shape[0], dtype=np.float64, order="C")
96
+ if not isinstance(class_weight, dict):
97
+ raise ValueError(
98
+ "class_weight must be dict, 'balanced', or None,"
99
+ " got: %r" % class_weight
100
+ )
101
+ for c in class_weight:
102
+ i = np.searchsorted(classes, c)
103
+ if i >= len(classes) or classes[i] != c:
104
+ raise ValueError("Class label {} not present.".format(c))
105
+ weight[i] = class_weight[c]
106
+
107
+ return weight
108
+
109
+
110
+ def _validate_targets(y, class_weight, dtype):
111
+ y_ = _column_or_1d(y, warn=True)
112
+ _check_classification_targets(y)
113
+ classes, y = np.unique(y_, return_inverse=True)
114
+ class_weight_res = _compute_class_weight(class_weight, classes=classes, y=y_)
115
+
116
+ if len(classes) < 2:
117
+ raise ValueError(
118
+ "The number of classes has to be greater than one; got %d"
119
+ " class" % len(classes)
120
+ )
121
+
122
+ return np.asarray(y, dtype=dtype, order="C"), class_weight_res, classes
123
+
124
+
125
+ def _check_array(
126
+ array,
127
+ dtype="numeric",
128
+ accept_sparse=False,
129
+ order=None,
130
+ copy=False,
131
+ force_all_finite=True,
132
+ ensure_2d=True,
133
+ accept_large_sparse=True,
134
+ ):
135
+ if force_all_finite:
136
+ if sp.issparse(array):
137
+ if hasattr(array, "data"):
138
+ _assert_all_finite(array.data)
139
+ force_all_finite = False
140
+ else:
141
+ _assert_all_finite(array)
142
+ force_all_finite = False
143
+ array = check_array(
144
+ array=array,
145
+ dtype=dtype,
146
+ accept_sparse=accept_sparse,
147
+ order=order,
148
+ copy=copy,
149
+ force_all_finite=force_all_finite,
150
+ ensure_2d=ensure_2d,
151
+ accept_large_sparse=accept_large_sparse,
152
+ )
153
+
154
+ if sp.issparse(array):
155
+ return array
156
+
157
+ # TODO: Convert this kind of arrays to a table like in daal4py
158
+ if not array.flags.aligned and not array.flags.writeable:
159
+ array = np.array(array.tolist())
160
+
161
+ # TODO: If data is not contiguous copy to contiguous
162
+ # Need implemeted numpy table in oneDAL
163
+ if not array.flags.c_contiguous and not array.flags.f_contiguous:
164
+ array = np.ascontiguousarray(array, array.dtype)
165
+ return array
166
+
167
+
168
+ def _check_X_y(
169
+ X,
170
+ y,
171
+ dtype="numeric",
172
+ accept_sparse=False,
173
+ order=None,
174
+ copy=False,
175
+ force_all_finite=True,
176
+ ensure_2d=True,
177
+ accept_large_sparse=True,
178
+ y_numeric=False,
179
+ accept_2d_y=False,
180
+ ):
181
+ if y is None:
182
+ raise ValueError("y cannot be None")
183
+
184
+ X = _check_array(
185
+ X,
186
+ accept_sparse=accept_sparse,
187
+ dtype=dtype,
188
+ order=order,
189
+ copy=copy,
190
+ force_all_finite=force_all_finite,
191
+ ensure_2d=ensure_2d,
192
+ accept_large_sparse=accept_large_sparse,
193
+ )
194
+
195
+ if not accept_2d_y:
196
+ y = _column_or_1d(y, warn=True)
197
+ else:
198
+ y = np.ascontiguousarray(y)
199
+
200
+ if y_numeric and y.dtype.kind == "O":
201
+ y = y.astype(np.float64)
202
+ if force_all_finite:
203
+ _assert_all_finite(y)
204
+
205
+ lengths = [X.shape[0], y.shape[0]]
206
+ uniques = np.unique(lengths)
207
+ if len(uniques) > 1:
208
+ raise ValueError(
209
+ "Found input variables with inconsistent numbers of"
210
+ " samples: %r" % [int(length) for length in lengths]
211
+ )
212
+
213
+ return X, y
214
+
215
+
216
+ def _check_classification_targets(y):
217
+ y_type = _type_of_target(y)
218
+ if y_type not in [
219
+ "binary",
220
+ "multiclass",
221
+ "multiclass-multioutput",
222
+ "multilabel-indicator",
223
+ "multilabel-sequences",
224
+ ]:
225
+ raise ValueError("Unknown label type: %r" % y_type)
226
+
227
+
228
+ def _type_of_target(y):
229
+ is_sequence, is_array = isinstance(y, Sequence), hasattr(y, "__array__")
230
+ is_not_string, is_sparse = not isinstance(y, str), sp.issparse(y)
231
+ valid = (is_sequence or is_array or is_sparse) and is_not_string
232
+
233
+ if not valid:
234
+ raise ValueError(
235
+ "Expected array-like (array or non-string sequence), " "got %r" % y
236
+ )
237
+
238
+ sparse_pandas = y.__class__.__name__ in ["SparseSeries", "SparseArray"]
239
+ if sparse_pandas:
240
+ raise ValueError("y cannot be class 'SparseSeries' or 'SparseArray'")
241
+
242
+ if _is_multilabel(y):
243
+ return "multilabel-indicator"
244
+
245
+ # DeprecationWarning will be replaced by ValueError, see NEP 34
246
+ # https://numpy.org/neps/nep-0034-infer-dtype-is-object.html
247
+ with warnings.catch_warnings():
248
+ warnings.simplefilter("error", VisibleDeprecationWarning)
249
+ try:
250
+ y = np.asarray(y)
251
+ except VisibleDeprecationWarning:
252
+ # dtype=object should be provided explicitly for ragged arrays,
253
+ # see NEP 34
254
+ y = np.asarray(y, dtype=object)
255
+
256
+ # The old sequence of sequences format
257
+ try:
258
+ if (
259
+ not hasattr(y[0], "__array__")
260
+ and isinstance(y[0], Sequence)
261
+ and not isinstance(y[0], str)
262
+ ):
263
+ raise ValueError(
264
+ "You appear to be using a legacy multi-label data"
265
+ " representation. Sequence of sequences are no"
266
+ " longer supported; use a binary array or sparse"
267
+ " matrix instead - the MultiLabelBinarizer"
268
+ " transformer can convert to this format."
269
+ )
270
+ except IndexError:
271
+ pass
272
+
273
+ # Invalid inputs
274
+ if y.ndim > 2 or (y.dtype == object and len(y) and not isinstance(y.flat[0], str)):
275
+ return "unknown" # [[[1, 2]]] or [obj_1] and not ["label_1"]
276
+
277
+ if y.ndim == 2 and y.shape[1] == 0:
278
+ return "unknown" # [[]]
279
+
280
+ if y.ndim == 2 and y.shape[1] > 1:
281
+ suffix = "-multioutput" # [[1, 2], [1, 2]]
282
+ else:
283
+ suffix = "" # [1, 2, 3] or [[1], [2], [3]]
284
+
285
+ # check float and contains non-integer float values
286
+ if y.dtype.kind == "f" and np.any(y != y.astype(int)):
287
+ # [.1, .2, 3] or [[.1, .2, 3]] or [[1., .2]] and not [1., 2., 3.]
288
+ _assert_all_finite(y)
289
+ return "continuous" + suffix
290
+
291
+ if (len(np.unique(y)) > 2) or (y.ndim >= 2 and len(y[0]) > 1):
292
+ return "multiclass" + suffix # [1, 2, 3] or [[1., 2., 3]] or [[1, 2]]
293
+ return "binary" # [1, 2] or [["a"], ["b"]]
294
+
295
+
296
+ def _is_integral_float(y):
297
+ return y.dtype.kind == "f" and np.all(y.astype(int) == y)
298
+
299
+
300
+ def _is_multilabel(y):
301
+ if hasattr(y, "__array__") or isinstance(y, Sequence):
302
+ # DeprecationWarning will be replaced by ValueError, see NEP 34
303
+ # https://numpy.org/neps/nep-0034-infer-dtype-is-object.html
304
+ with warnings.catch_warnings():
305
+ warnings.simplefilter("error", VisibleDeprecationWarning)
306
+ try:
307
+ y = np.asarray(y)
308
+ except VisibleDeprecationWarning:
309
+ # dtype=object should be provided explicitly for ragged arrays,
310
+ # see NEP 34
311
+ y = np.array(y, dtype=object)
312
+
313
+ if not (hasattr(y, "shape") and y.ndim == 2 and y.shape[1] > 1):
314
+ return False
315
+
316
+ if sp.issparse(y):
317
+ if isinstance(y, (sp.dok_matrix, sp.lil_matrix)):
318
+ y = y.tocsr()
319
+ return (
320
+ len(y.data) == 0
321
+ or np.unique(y.data).size == 1
322
+ and (y.dtype.kind in "biu" or _is_integral_float(np.unique(y.data)))
323
+ )
324
+ labels = np.unique(y)
325
+
326
+ return len(labels) < 3 and (y.dtype.kind in "biu" or _is_integral_float(labels))
327
+
328
+
329
+ def _check_n_features(self, X, reset):
330
+ try:
331
+ n_features = _num_features(X)
332
+ except TypeError as e:
333
+ if not reset and hasattr(self, "n_features_in_"):
334
+ raise ValueError(
335
+ "X does not contain any features, but "
336
+ f"{self.__class__.__name__} is expecting "
337
+ f"{self.n_features_in_} features"
338
+ ) from e
339
+ # If the number of features is not defined and reset=True,
340
+ # then we skip this check
341
+ return
342
+
343
+ if reset:
344
+ self.n_features_in_ = n_features
345
+ return
346
+
347
+ if not hasattr(self, "n_features_in_"):
348
+ # Skip this check if the expected number of expected input features
349
+ # was not recorded by calling fit first. This is typically the case
350
+ # for stateless transformers.
351
+ return
352
+
353
+ if n_features != self.n_features_in_:
354
+ raise ValueError(
355
+ f"X has {n_features} features, but {self.__class__.__name__} "
356
+ f"is expecting {self.n_features_in_} features as input."
357
+ )
358
+
359
+
360
+ def _num_features(X, fallback_1d=False):
361
+ type_ = type(X)
362
+ if type_.__module__ == "builtins":
363
+ type_name = type_.__qualname__
364
+ else:
365
+ type_name = f"{type_.__module__}.{type_.__qualname__}"
366
+ message = "Unable to find the number of features from X of type " f"{type_name}"
367
+ if not hasattr(X, "__len__") and not hasattr(X, "shape"):
368
+ if not hasattr(X, "__array__"):
369
+ raise TypeError(message)
370
+ # Only convert X to a numpy array if there is no cheaper, heuristic
371
+ # option.
372
+ X = np.asarray(X)
373
+
374
+ if hasattr(X, "shape"):
375
+ ndim_thr = 1 if fallback_1d else 2
376
+ if not hasattr(X.shape, "__len__") or len(X.shape) < ndim_thr:
377
+ message += f" with shape {X.shape}"
378
+ raise TypeError(message)
379
+ return X.shape[-1]
380
+
381
+ first_sample = X[0]
382
+
383
+ # Do not consider an array-like of strings or dicts to be a 2D array
384
+ if isinstance(first_sample, (str, bytes, dict)):
385
+ message += f" where the samples are of type " f"{type(first_sample).__qualname__}"
386
+ raise TypeError(message)
387
+
388
+ try:
389
+ # If X is a list of lists, for instance, we assume that all nested
390
+ # lists have the same length without checking or converting to
391
+ # a numpy array to keep this function call as cheap as possible.
392
+ if (not fallback_1d) or hasattr(first_sample, "__len__"):
393
+ return len(first_sample)
394
+ else:
395
+ return 1
396
+ except Exception as err:
397
+ raise TypeError(message) from err
398
+
399
+
400
+ def _num_samples(x):
401
+ message = "Expected sequence or array-like, got %s" % type(x)
402
+ if hasattr(x, "fit") and callable(x.fit):
403
+ # Don't get num_samples from an ensembles length!
404
+ raise TypeError(message)
405
+
406
+ if not hasattr(x, "__len__") and not hasattr(x, "shape"):
407
+ if hasattr(x, "__array__"):
408
+ x = np.asarray(x)
409
+ else:
410
+ raise TypeError(message)
411
+
412
+ if hasattr(x, "shape") and x.shape is not None:
413
+ if len(x.shape) == 0:
414
+ raise TypeError(
415
+ "Singleton array %r cannot be considered a valid collection." % x
416
+ )
417
+ # Check that shape is returning an integer or default to len
418
+ # Dask dataframes may not return numeric shape[0] value
419
+ if hasattr(x, "shape") and isinstance(x.shape[0], Integral):
420
+ return x.shape[0]
421
+
422
+ try:
423
+ return len(x)
424
+ except TypeError as type_error:
425
+ raise TypeError(message) from type_error
426
+
427
+
428
+ def _is_csr(x):
429
+ """Return True if x is scipy.sparse.csr_matrix or scipy.sparse.csr_array"""
430
+ return isinstance(x, sp.csr_matrix) or (
431
+ hasattr(sp, "csr_array") and isinstance(x, sp.csr_array)
432
+ )
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+ Copyright 2017, The TensorFlow Authors.
189
+
190
+ Licensed under the Apache License, Version 2.0 (the "License");
191
+ you may not use this file except in compliance with the License.
192
+ You may obtain a copy of the License at
193
+
194
+ http://www.apache.org/licenses/LICENSE-2.0
195
+
196
+ Unless required by applicable law or agreed to in writing, software
197
+ distributed under the License is distributed on an "AS IS" BASIS,
198
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
199
+ See the License for the specific language governing permissions and
200
+ limitations under the License.
201
+
202
+ * Other names and brands may be claimed as the property of others.