When using scikit learn or other similar Python libraries, what's the difference between doing:
import sklearn.cluster as sk
model = sk.KMeans(n_clusters=n)
And
from sklearn.cluster import KMeans
model = KMeans(n_clusters=n)
Is there any advantage to using one way over the other?
Well, in your first example, you've made the module
sklearn.cluster
accessible assk
and you can refer to its members accordingly. In your second example, you've only imported one member ofsklearn.cluster
,KMeans
, so only that one is accessible. That's the difference.As for advantages? Do whichever makes your code easier to read.