Search code examples
pythonpython-3.xscikit-learngaussiansklearn-pandas

ModuleNotFoundError: No module named 'sklearn.naive_bytes'; 'sklearn' is not a package


I have already installed sklearn, but still when I run the program it shows error. When I try to check if it is install it says requirements are already satisfied.

import numpy as np 
X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
Y = np.array([1, 1, 1, 2, 2, 2])
from sklearn.naive_bayes import GaussianNB
clf = GaussianNB()
clf.fit(X, Y)
GaussianNB()
print(clf.predict([[-0.8, -1]]))
clf_pf = GaussianNB()
clf_pf.partial_fit(X, Y, np.unique(Y))
GaussianNB()
print(clf_pf.predict([[-0.8, -1]]))

The output for the same is as given in the image below. enter image description here


Solution

  • You need to rename your file from "sklearn.py" to something else. Try renaming it to "foo.py" then run

    python foo.py