# 导入库import numpy as np# 共 100 个样本每个样本 x 都包括 5 个特征nprandomseed0x = nprandomrandn100 5# 共 100 个样本每个样本 x 都属于 01 类别中的一个nprandomseed0y = nprandomrandint02100# 给定 xx = 01011xx = nparray01011setx = # setxi
任务1:根据条件独立假设,求样本 xx 属于 i 类别的概率
for i in range(2): for j in range(5): mean = np.mean(setx[i][:, j]) std = np.std(setx[i][:, j]) p[i] *= normal(xx[j], mean, std)
任务2:根据连续型朴素贝叶斯判定准则,求样本 xx 属于哪个类别的概率最大
label = np.argmax(p)
原文地址: https://www.cveoy.top/t/topic/eoD4 著作权归作者所有。请勿转载和采集!