pythonmachine-learningscikit-learnnaivebayes

How to tune GaussianNB?


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?


Solution

  • 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_