How to tune GaussianNB?

vlad picture vlad · Oct 3, 2016 · Viewed 10.2k times · Source

Trying to fit data with GaussianNB() gives me low accuracy score.

I'd like to try Grid Search, but it seems that parameters sigma and theta cannot be set. Is there anyway to tune GausssianNB?

Answer

ana picture ana · Nov 3, 2020

You can tune 'var_smoothing' parameter like this:

nb_classifier = GaussianNB()

params_NB = {'var_smoothing': np.logspace(0,-9, num=100)}
gs_NB = GridSearchCV(estimator=nb_classifier, 
                 param_grid=params_NB, 
                 cv=cv_method,   # use any cross validation technique 
                 verbose=1, 
                 scoring='accuracy') 
gs_NB.fit(x_train, y_train)

gs_NB.best_params_