py.importl​ib.import_​module('gp​learn') ???

10 ビュー (過去 30 日間)
slevin Lee
slevin Lee 2022 年 11 月 7 日
回答済み: Rushikesh 2024 年 9 月 17 日
gplearn = py.importlib.import_module('gplearn');
sklearn = py.importlib.import_module('sklearn');
why they are different???

回答 (1 件)

Rushikesh
Rushikesh 2024 年 9 月 17 日
This is the intended behaviour, and it is due to the structure of these modules.
In “__init__.py” file of ‘sklearn’ library, you will find that it is importing several submodules and functions to be available directly from ‘sklearn’ namespace. Where as ‘gplearn’ library does not expose anything at top level when imported. It is related with how packages defined in there their ‘__init__.py’ file.
Added advantage of many properties get imported with ‘sklearn’ can be seen in below example. Let’s say you want to use ‘clone’ function of ‘sklearn’ then consider below scenarios:
1. Without importing submodules, functions at Top level:
from sklearn.base import clone
2. With importing submodules, functions at Top level:
from sklearn import clone

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by