I am replying this example in my code:
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(priors=None, var_smoothing=1e-09)
print(clf.predict([[-0.8, -1]]))
which is presented here: GaussianNB documentation.
I get
GaussianNB(priors=None, var_smoothing=1e-09)
TypeError: __init__() got an unexpected keyword argument 'var_smoothing'
The version of sklearn is
>>> import sklearn
>>> print(sklearn.__version__)
0.19.2
Does anybody know what is happening and how to solve it?
The current version of sci-kit learn is 0.21.2.
I tested this out in sklearn version 0.19.2
. The parameter var_smoothing
is not defined for the GaussianNB
method.
You can check this out by using the documentation
from sklearn.naive_bayes import GaussianNB
help(GaussianNB)
# Result
Help on class GaussianNB in module sklearn.naive_bayes:
class GaussianNB(BaseNB)
| Gaussian Naive Bayes (GaussianNB)
...
...
| Parameters
| ----------
| priors : array-like, shape (n_classes,)
| Prior probabilities of the classes. If specified the priors are not
| adjusted according to the data.
|
| Attributes
...
...
You can upgrade to the latest version of scikit learn or just remove the parameter.