Press "Enter" to skip to content

Naive Bayes Basic

Naive Bayes Basic

用sklearn去拟合NB模型

➜ test ✗ cat nb.py
import numpy as np
from sklearn.naive_bayes import GaussianNB
# 创建训练坐标(输入X求得Y)
X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
Y = np.array([1, 1, 1, 2, 2, 2])
# 创建Naive Bayes分类器
clf = GaussianNB()
# 对数据进行拟合
clf.fit(X, Y)
# 进行预测, 输出结果
print(clf.predict([[-0.8, -1]]))

预测结果

➜ test ✗ python3 nb.py
[1]

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *