File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
doc/whats_new/upcoming_changes/many-modules Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change
1
+ - Scikit-learn classes and functions can be used while only having a
2
+ `import sklearn ` import line. For example, `import sklearn; sklearn.svm.SVC() ` now works.
3
+ By :user: `Thomas Fan <thomasjpfan> `
Original file line number Diff line number Diff line change 16
16
#
17
17
# See https://scikit-learn.org for complete documentation.
18
18
19
+ import importlib as _importlib
19
20
import logging
20
21
import os
21
22
import random
72
73
from .base import clone # noqa: E402
73
74
from .utils ._show_versions import show_versions # noqa: E402
74
75
75
- __all__ = [
76
+ _submodules = [
76
77
"calibration" ,
77
78
"cluster" ,
78
79
"covariance" ,
110
111
"discriminant_analysis" ,
111
112
"impute" ,
112
113
"compose" ,
114
+ ]
115
+
116
+ __all__ = _submodules + [
113
117
# Non-modules:
114
118
"clone" ,
115
119
"get_config" ,
118
122
"show_versions" ,
119
123
]
120
124
125
+
126
+ def __dir__ ():
127
+ return __all__
128
+
129
+
130
+ def __getattr__ (name ):
131
+ if name in _submodules :
132
+ return _importlib .import_module (f"sklearn.{ name } " )
133
+ else :
134
+ try :
135
+ return globals ()[name ]
136
+ except KeyError :
137
+ raise AttributeError (f"Module 'sklearn' has no attribute '{ name } '" )
138
+
139
+
121
140
_BUILT_WITH_MESON = False
122
141
try :
123
142
import sklearn ._built_with_meson # noqa: F401
You can’t perform that action at this time.
0 commit comments