question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exposing submodules directly from main sklearn module instead of recursively importing each submodule separately

See original GitHub issue

Describe 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:open
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
thomasjpfancommented, Apr 24, 2022

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:

import scipy as sp

sp.linalg.eig(...)

The issue and a lazy loading solution are described in Scientific Python Enhancement Proposal 1.

1reaction
glemaitrecommented, Apr 27, 2022

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:

  • is there any memory and runtime overhead in the multiprocessing setting?
Read more comments on GitHub >

github_iconTop Results From Across the Web

importing whole python module doesn't allow using submodules
This object is the bound to the name sklearn . Submodules are not implicitly imported by the interpreter. However when doing from sklearn...
Read more >
How To Build Python Packages - Oak-Tree Technologies
Submodule -linked Repository. Separate documentation, testing, and code repositories with a "packaing" repository that links them through Git ...
Read more >
API Reference — scikit-learn 1.2.0 documentation
The sklearn.datasets module includes utilities to load datasets, including methods to load and fetch popular reference datasets.
Read more >
mkinit - PyPI
mkinit automatically imports all submodules in a package and their members. ... use relative import statements, maybe you only want to expose submodule...
Read more >
Git - Submodules - Git SCM
To also initialize, fetch and checkout any nested submodules, you can use the foolproof git submodule update --init --recursive . Working on a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found