0

In order to use a classifier (e.g. KNeighborsClassifier) in Python, it is necessary to type

from sklearn.neighbors import KNeighborsClassifier

I am not sure if sklearn is a module, package or class? What is sklearn.neighbors called? And finally, how would we name KNeighborsClassifier?

I am looking for the right terminology to use when talking about these topics.

MrYouMath
  • 547
  • 2
  • 13
  • 34

1 Answers1

1

sklearn.neighbors is a module. KNeighborsClassifier is a class. sklearn is also a module, but in the case of sklearn.neighbors it's just part of the name and not referring to the sklearn module.

Probie
  • 1,371
  • 7
  • 15
  • Plus one. What is a package then? – MrYouMath May 01 '18 at 13:13
  • 1
    A package is a directory which can contain python modules and other packages and must contain an `__init__.py` (which can be empty). `sklearn.neighbors` belongs to the `sklearn` package, because it's in a directory called `sklearn`. So the "it's just part of the name" might have been a bit misleading, since the name of the `sklearn.neighbors` module is `sklearn.neighbors`, but having that name also tells you that it's part of the `sklearn` package. – Probie May 01 '18 at 13:21
  • So does package and module mean the same? – MrYouMath May 01 '18 at 13:23
  • 1
    Not quite, a module can just be a single python file. A package must be an entire folder containing `__init__.py`. All packages are modules though - you can import a package, just like a module, but it may not necessarily import every module in the package - that's up to the person who made the package. For example, loading `sklearn` doesn't load the `sklearn.neighbors` module, even though it's in the `sklearn` package. You have to do that explicitly. – Probie May 01 '18 at 13:27
  • Thank you for your help :). – MrYouMath May 01 '18 at 13:35