Issue
Can anyone please help me understand the module structure of python and how the import works in python.
I wanted to use the linear_model
of sklearn module in python but these two different codes are acting differently whereas they should have acted the same way. One is giving error and another one is working fine.
Look at the code in this picture...
import sklearn as sk # gives error
from sklearn import linear_model # works fine
Solution
import sklearn
corresponds to importing sklearn/__init__.py
.
That module does not re-export the subpackage sklearn.linear_model
(sklearn/linear_model/__init__.py
) as an attribute.
There's no reason why they should act the same way. Some packages do re-exporting, many (scikit-learn included) don't.
Answered By - AKX
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.