尝试用GaussianNB()拟合数据会给我带来较低的准确性分数。我想尝试网格搜索,但似乎无法设置参数sigma和theta。是否有任何方法可以调优GausssianNB?
GaussianNB()
sigma
theta
GausssianNB
wqlqzqxt1#
您可以像这样调整'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_
8aqjt8rx2#
截至version 0.20GaussianNB().get_params().keys()返回'priors'和'var_smoothing'网格搜索看起来像这样:
GaussianNB().get_params().keys()
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)
g52tjvyc3#
在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)
ecbunoof4#
朴素贝叶斯不需要调整任何超参数。
4条答案
按热度按时间wqlqzqxt1#
您可以像这样调整'var_smoothing'参数:
8aqjt8rx2#
截至version 0.20
GaussianNB().get_params().keys()
返回'priors'和'var_smoothing'网格搜索看起来像这样:
g52tjvyc3#
在sklearn管道中,它可能看起来如下所示:
ecbunoof4#
朴素贝叶斯不需要调整任何超参数。