I'm beginning to do some machine learning in Python, and I'm just starting to use the sklearn
package. In my experience with Python data science programming, there are conventions for naming imported packages; for example, import pandas as pd
, or import numpy as np
.
Thus far, I've only ever seen code where a single function, etc. is imported from sklearn, rather than the entirety of the package. If I were to import sklearn, what convention would be used. In other words, import sklearn as
--what?
(Of course, if I haven't seen it yet, it's entirely possible that it means that convention is specifically to not import the entirety of sklearn at a time.... If that's the case, please let me know that too. Thanks.)
Import just the classes that you need. Unlike with numpy, it is likely to be a pretty small subset and slower-changing subset of the module. For example
from sklearn.ensemble import RandomForestClassifier
...
est = RandomForestClassifier()