pybear-dask 0.2.0__py3-none-any.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.
Files changed (33) hide show
  1. pybear_dask/__init__.py +19 -0
  2. pybear_dask/_version.py +38 -0
  3. pybear_dask/base/__init__.py +24 -0
  4. pybear_dask/base/_is_classifier.py +186 -0
  5. pybear_dask/model_selection/GSTCV/_GSTCVDask/GSTCVDask.py +918 -0
  6. pybear_dask/model_selection/GSTCV/_GSTCVDask/__init__.py +5 -0
  7. pybear_dask/model_selection/GSTCV/_GSTCVDask/_fit/__init__.py +5 -0
  8. pybear_dask/model_selection/GSTCV/_GSTCVDask/_fit/_estimator_fit_params_helper.py +106 -0
  9. pybear_dask/model_selection/GSTCV/_GSTCVDask/_fit/_fold_splitter.py +86 -0
  10. pybear_dask/model_selection/GSTCV/_GSTCVDask/_fit/_get_kfold.py +117 -0
  11. pybear_dask/model_selection/GSTCV/_GSTCVDask/_fit/_parallelized_fit.py +127 -0
  12. pybear_dask/model_selection/GSTCV/_GSTCVDask/_fit/_parallelized_scorer.py +228 -0
  13. pybear_dask/model_selection/GSTCV/_GSTCVDask/_fit/_parallelized_train_scorer.py +226 -0
  14. pybear_dask/model_selection/GSTCV/_GSTCVDask/_param_conditioning/__init__.py +5 -0
  15. pybear_dask/model_selection/GSTCV/_GSTCVDask/_param_conditioning/_scheduler.py +88 -0
  16. pybear_dask/model_selection/GSTCV/_GSTCVDask/_type_aliases.py +43 -0
  17. pybear_dask/model_selection/GSTCV/_GSTCVDask/_validation/__init__.py +5 -0
  18. pybear_dask/model_selection/GSTCV/_GSTCVDask/_validation/_cache_cv.py +37 -0
  19. pybear_dask/model_selection/GSTCV/_GSTCVDask/_validation/_dask_estimator.py +84 -0
  20. pybear_dask/model_selection/GSTCV/_GSTCVDask/_validation/_iid.py +38 -0
  21. pybear_dask/model_selection/GSTCV/_GSTCVDask/_validation/_validation.py +54 -0
  22. pybear_dask/model_selection/GSTCV/_GSTCVDask/_validation/_y.py +91 -0
  23. pybear_dask/model_selection/GSTCV/__init__.py +5 -0
  24. pybear_dask/model_selection/__init__.py +28 -0
  25. pybear_dask/model_selection/autogridsearch/AutoGSTCVDask.py +71 -0
  26. pybear_dask/model_selection/autogridsearch/AutoGridSearchCVDask.py +70 -0
  27. pybear_dask/model_selection/autogridsearch/__init__.py +19 -0
  28. pybear_dask/model_selection/autogridsearch/_autogridsearch_wrapper/__init__.py +5 -0
  29. pybear_dask/model_selection/autogridsearch/_autogridsearch_wrapper/_refit_can_be_skipped.py +100 -0
  30. pybear_dask-0.2.0.dist-info/LICENSE +28 -0
  31. pybear_dask-0.2.0.dist-info/METADATA +253 -0
  32. pybear_dask-0.2.0.dist-info/RECORD +33 -0
  33. pybear_dask-0.2.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,19 @@
1
+ # Author:
2
+ # Bill Sousa
3
+ #
4
+ # License: BSD 3 clause
5
+ #
6
+
7
+
8
+
9
+ from ._version import __version__
10
+ from ._version import __version_tuple__
11
+
12
+ __all__ = [
13
+ "model_selection",
14
+ "__version__"
15
+ ]
16
+
17
+
18
+
19
+
@@ -0,0 +1,38 @@
1
+ # Author:
2
+ # Bill Sousa
3
+ #
4
+ # License: BSD 3 clause
5
+ #
6
+
7
+
8
+ from typing import Tuple
9
+ from typing_extensions import Union
10
+ import numpy as np
11
+
12
+
13
+ try:
14
+ from importlib.metadata import version as get_version
15
+ except ImportError:
16
+ # For older Python versions, use importlib-metadata package
17
+ from importlib_metadata import version as get_version
18
+
19
+
20
+ version: str
21
+ __version__: str
22
+ VERSION_TUPLE = Tuple[Union[int, str], ...]
23
+ version_tuple: VERSION_TUPLE
24
+ __version_tuple__: VERSION_TUPLE
25
+
26
+ __version__ = version = get_version('pybear-dask')
27
+ dot_idxs = np.arange(len(__version__))[np.array(list(__version__)) == '.']
28
+ dot_idxs = list(map(int, dot_idxs))
29
+ __version_tuple__ = version_tuple = (
30
+ int(__version__[:dot_idxs[0]]),
31
+ int(__version__[dot_idxs[0]+1:dot_idxs[1]]),
32
+ int(__version__[dot_idxs[1]+1:])
33
+ )
34
+
35
+
36
+
37
+
38
+
@@ -0,0 +1,24 @@
1
+ # Author:
2
+ # Bill Sousa
3
+ #
4
+ # License: BSD 3 clause
5
+ #
6
+
7
+
8
+
9
+ from ._is_classifier import is_classifier
10
+
11
+
12
+
13
+ __all__ = [
14
+ 'is_classifier',
15
+ ]
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
@@ -0,0 +1,186 @@
1
+ # Authors:
2
+ #
3
+ # Bill Sousa
4
+ #
5
+ # License: BSD 3 clause
6
+
7
+
8
+
9
+ import importlib
10
+ from sklearn.pipeline import Pipeline
11
+ from sklearn.base import is_classifier as sk_is_classifier
12
+
13
+
14
+
15
+ def is_classifier(estimator_) -> bool:
16
+ """Return True if the given estimator is a classifier, False otherwise.
17
+
18
+ Works on stand-alone and nested scikit-style estimators. This module
19
+ was originally intended to extend the functionality of scikit-learn's
20
+ is_classifier function to work on dask_ml estimators, but it also
21
+ works on xgboost and lightgbm estimators.
22
+
23
+ Support for scikit-learn wrappers includes, but may not be limited to:
24
+ CalibratedClassifierCV
25
+
26
+ GridSearchCV
27
+
28
+ Pipeline
29
+
30
+ Support for dask_ml wrappers includes, but may not be limited to:
31
+ GridSearchCV
32
+
33
+ Incremental
34
+
35
+ ParallelPostFit
36
+
37
+ BlockwiseVotingClassifier
38
+
39
+ BlockwiseVotingRegressor
40
+
41
+ Parameters
42
+ ----------
43
+ estimator_ : object
44
+ scikit-learn, dask_ml, xgboost, or lightgbm estimator to test.
45
+
46
+ Returns
47
+ -------
48
+ _is_classifier : bool
49
+ True if the estimator is a classifier, False otherwise.
50
+
51
+ See Also
52
+ --------
53
+ sklearn.base.is_classifier
54
+
55
+ Notes
56
+ -----
57
+ Also supports non-estimator objects, returning False for any object
58
+ that is not a classifier.
59
+
60
+ Examples
61
+ --------
62
+ >>> from pybear_dask.base import is_classifier
63
+ >>> from sklearn.linear_model import LogisticRegression, LinearRegression
64
+ >>> sk_clf = LogisticRegression()
65
+ >>> is_classifier(sk_clf)
66
+ True
67
+ >>> sk_reg = LinearRegression()
68
+ >>> is_classifier(sk_reg)
69
+ False
70
+
71
+ """
72
+
73
+
74
+ try:
75
+ if sk_is_classifier(estimator_):
76
+ return True
77
+ except:
78
+ try:
79
+ if sk_is_classifier(estimator_()):
80
+ return True
81
+ except:
82
+ pass
83
+
84
+ # USE RECURSION TO GET INNERMOST ESTIMATOR ** ** ** ** ** ** ** ** ** ** **
85
+ recursion_ct = 0
86
+
87
+ def retrieve_core_estimator_recursive(_estimator_, recursion_ct):
88
+
89
+ recursion_ct += 1
90
+ if recursion_ct == 10:
91
+ raise Exception(f"too many recursions, abort")
92
+
93
+ if 'delayed.delayed' in str(type(_estimator_)).lower():
94
+ return _estimator_
95
+
96
+ for _module in [
97
+ 'blockwisevoting',
98
+ 'calibratedclassifier',
99
+ 'gradientboosting'
100
+ ]:
101
+
102
+ if str(_estimator_).lower().startswith(_module):
103
+ # escape when have dug deep enough that _module is the
104
+ # outermost wrapper. use hard strings, dont import the
105
+ # actual modules to avoid circular imports
106
+ return _estimator_
107
+
108
+ try:
109
+ _estimator_ = _estimator_.estimator
110
+ except:
111
+ if isinstance(_estimator_, Pipeline):
112
+ _estimator_ = _estimator_.steps[-1][-1]
113
+ else:
114
+ return _estimator_
115
+
116
+ return retrieve_core_estimator_recursive(_estimator_, recursion_ct)
117
+
118
+ estimator_ = retrieve_core_estimator_recursive(estimator_, recursion_ct)
119
+
120
+ # END USE RECURSION TO GET INNERMOST ESTIMATOR ** ** ** ** ** ** ** ** ** *
121
+
122
+ try:
123
+ if sk_is_classifier(estimator_):
124
+ return True
125
+ except:
126
+ try:
127
+ if sk_is_classifier(estimator_()):
128
+ return True
129
+ except:
130
+ pass
131
+
132
+ if 'calibratedclassifier' in str(estimator_).lower():
133
+ return True
134
+ elif 'blockwisevoting' in str(estimator_).lower():
135
+ # use hard strings, dont import the actual modules to avoid
136
+ # circular imports
137
+ return sk_is_classifier(estimator_)
138
+
139
+ try:
140
+ _path = str(estimator_().__class__)
141
+ except:
142
+ _path = str(estimator_.__class__)
143
+
144
+ dask_supported = [
145
+ 'lightgbm', 'xgboost', 'dask.delayed', 'dask.array', 'dask.dataframe',
146
+ 'dask_expr._collection.DataFrame'
147
+ ]
148
+
149
+ if 'dask' in _path and all([x not in _path for x in dask_supported]):
150
+ # use hard strings, dont import the actual modules to avoid
151
+ # circular imports
152
+ _path = _path[_path.find("'", 0, -1) + 1:_path.find("'", -1, 0) - 1]
153
+
154
+ _split = _path.split(sep='.')
155
+ if len(_split) == 4: _split.pop(-2)
156
+
157
+ _split[0] = 'sklearn'
158
+
159
+ _package = ".".join(_split[:2])
160
+
161
+ if _split[-1] == 'PoissonRegression':
162
+ _function = 'PoissonRegressor'
163
+ else:
164
+ _function = _split[-1]
165
+
166
+ _base_err_msg = f"is_classifier() excepted trying to import "
167
+ try:
168
+ sklearn_module = importlib.import_module(_package)
169
+ except:
170
+ raise ImportError(_base_err_msg + f"{_package}")
171
+ try:
172
+ sklearn_dummy_function = getattr(sklearn_module, _function)
173
+ except:
174
+ raise ImportError(_base_err_msg + f"{_function} from {_package}")
175
+
176
+ return sk_is_classifier(sklearn_dummy_function)
177
+
178
+ return False
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+