""" 朴素贝叶斯模型(Naive Bayesian Model,NBM) 算法示例 20221110 来源:https://blog.csdn.net/weixin_43849505/article/details/118733892 """ import numpy as np from sklearn.naive_bayes import GaussianNB # 引入库文件 X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]]) Y = np.array([1, 1, 1, 2, 2, 2]) # 构造训练数据 clf = GaussianNB(priors=None) # 使用默认参数,创建一个高斯朴素贝叶斯分类器 clf.fit(X, Y) # 传入数据 print(clf.predict([[-0.8,-1]])) # 进行预测