Exposing submodules directly from main sklearn module instead of recursively importing each submodule separately
See original GitHub issueDescribe the workflow you want to enable
The problem that I’m facing is the same as the issue described in this stackoverflow page. Basically sklearn lacks the ability to allow users flexibility in how they would like to import submodules.
For instance, if someone wants to use x,y,z,...,etc
submodule form sklearn they would have to do the following for each of them:
from sklearn.x import x
from sklearn.y import y
from sklearn.z import z
This not only increases the line of codes in a codebase but also makes core readability more difficult to follow, especially in large code bases.
Describe your proposed solution
The best thing would be to enable the same functionality as numpy.
For instance, in numpy all we have to do is import numpy as np
and all the magic is in the np.
namespace.
I would really like to be able to do the same thing with sklearn, e.g., import sklearn as sk
and then calling the different submodules as needed, e.g., sk.metrics.auccuracy
or sk.model_selection.cross_validate
, etc.
At least this is a coherent way of reading the code and understanding much easier where each submodule came from.
I really don’t know why sklearn has avoided this kind of exposure of submodules since all other major libraries do it, e.g., import pandas as pd
?
Describe alternatives you’ve considered, if relevant
No response
Additional context
No response
Issue Analytics
- State:
- Created a year ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
There is overhead in loading all the submodules. scikit-learn is more similar to SciPy, where most functionality are in submodules. For example, the following does not work in SciPy:
The issue and a lazy loading solution are described in Scientific Python Enhancement Proposal 1.
We discussed this issue during the developer meeting on April 25. The conclusion was that we need to experiment before making a decision. Notably, we should investigate the following: