shaare.it

ValueError: GaussianNB 'var_smoothing' must be float

ValueError: GaussianNB var_smoothing invalid type

$ python -c "from sklearn.naive_bayes import GaussianNB; GaussianNB(var_smoothing='auto').fit([[0],[1]],[0,1])"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ValueError: var_smoothing must be a float

Why this happens

Wrong type passed.

Fix

Use a float value like 1e-9.

Wrong code

from sklearn.naive_bayes import GaussianNB
GaussianNB(var_smoothing='auto')

Fixed code

from sklearn.naive_bayes import GaussianNB
GaussianNB(var_smoothing=1e-9)