朴素贝叶斯算法系列:多项式贝叶斯、高斯贝叶斯、伯努利贝叶斯

导入库

from sklearn.naive_bayes import MultinomialNB, GaussianNB, BernoulliNB

多项式贝叶斯

def MultinomialNB_Classifier(self, fea_train, trainLabel,testPadSqe):
    """模型算法:
    多项式贝叶斯算法
    """
    clf = MultinomialNB(alpha=1e-10)     
    clf.fit(fea_train,np.array(trainLabel))
    # model = joblib.dump(clf, modelsavepath)
    #
    # if (os.path.exists(modelsavepath)):
    #     print("Load......")
    #     clf = joblib.load(modelsavepath)
    #     pred = clf.predict(testPadSqe)
    #
    # else:
    #     print("模型不存在。")

    pred = clf.predict(testPadSqe)

    return pred

伯努利贝叶斯

def BernoulliNB_Classifier(self, fea_train, trainLabel,testPadSqe):
    """模型算法:
    伯努利贝叶斯算法
    """
    clf = BernoulliNB()     
    clf.fit(fea_train,np.array(trainLabel))
    # model = joblib.dump(clf, modelsavepath)
    #
    # if (os.path.exists(modelsavepath)):
    #     print("Load......")
    #     clf = joblib.load(modelsavepath)
    #     pred = clf.predict(testPadSqe)
    #
    # else:
    #     print("模型不存在。")

    pred = clf.predict(testPadSqe)

    return pred

高斯贝叶斯

def GaussianNB_Classifier(self, fea_train, trainLabel,testPadSqe):
    """模型算法:
    高斯贝叶斯算法
    """
    clf = GaussianNB()    
    clf.fit(fea_train,np.array(trainLabel))
    # model = joblib.dump(clf, modelsavepath)
    #
    # if (os.path.exists(modelsavepath)):
    #     print("Load......")
    #     clf = joblib.load(modelsavepath)
    #     pred = clf.predict(testPadSqe)
    #
    # else:
    #     print("模型不存在。")

    pred = clf.predict(testPadSqe)

    return pred

猜你喜欢

转载自blog.csdn.net/Stybill_LV_/article/details/110858869
今日推荐