如何调整GuassianNB?

时间:2016-10-03 09:35:14

标签: machine-learning scikit-learn naivebayes

尝试使用GuassianNB()拟合数据会给我低准确度分数。

我想尝试网格搜索,但似乎无法设置参数sigmatheta。无论如何都要调整GuassianNB

4 个答案:

答案 0 :(得分:1)

您可以像这样调整“ var_smoothing ”参数:

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_

答案 1 :(得分:1)

在 sklearn 管道中,它可能如下所示:

pipe = Pipeline(steps=[
                    ('pca', PCA()),
                    ('estimator', GaussianNB()),
                    ])
    
parameters = {'estimator__var_smoothing': [1e-11, 1e-10, 1e-9]}
Bayes = GridSearchCV(pipe, parameters, scoring='accuracy', cv=10).fit(X_train, y_train)
print(Bayes.best_estimator_)
print('best score:')
print(Bayes.best_score_)
predictions = Bayes.best_estimator_.predict(X_test)

答案 2 :(得分:0)

朴素贝叶斯(Bayes)没有任何要调整的超参数。

答案 3 :(得分:0)

截至version 0.20

GaussianNB().get_params().keys() 返回“ priors”和“ var_smoothing”

网格搜索如下:

pipeline = Pipeline([
    ('clf', GaussianNB())
])

parameters = {
    'clf__priors': [None],
    'clf__var_smoothing': [0.00000001, 0.000000001, 0.00000001]
}

cv = GridSearchCV(pipeline, param_grid=parameters)

cv.fit(X_train, y_train)
y_pred_gnb = cv.predict(X_test)